php - strpos always returning true -
my code return "true" whatever string tried bunch of thing return false... have no idea can fix this... code:
public function isblacklisted($string) { $apis = mysql_connect("mysql.hostinger.fr", "mysql user", "testpass") or die(mysql_error()); mysql_select_db("u770656121_api", $apis); $sql = "select * blacklist"; $result = mysql_query($sql, $apis); while($row = mysql_fetch_array($result)) { $username = $row['username']; if (strpos($string,$username) !== 0) { return true; break; } else { return false; break; } } }
strpos
returns false
is not found, , 0
if in first position of string. sounds want do:
if (strpos($string,$username) !== false) {
also, looping on db results, should return if found:
while($row = mysql_fetch_array($result)) { $username = $row['username']; if (strpos($string,$username) !== false) { return true; } } return false;
or, better:
$sql = "select * blacklist 'username' '%$username%'"; $result = mysql_query($sql, $apis); while($row = mysql_fetch_array($result)) { if ($row['username']) return true; }
making sure escape $username
, ideally switching mysqli
or pdo
instead of using deprecated mysql
statements.
Comments
Post a Comment