Php problems

Codes here !

Moderators: macek, egami, gesf

joeybab3
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 02, 2014 2:06 pm

Php problems

Postby joeybab3 » Wed Jan 22, 2014 10:54 pm

After having terrible luck on stack overflow...(just getting let me google that for you links), i have looked over 100's of pages describing my problem and none fit the bill. heres my code that it doesn't like:
$num_rows = $db->num_rows($query);
it replies:
Fatal error: Call to undefined method mysqli::num_rows() in /path/users.php on line 23
full code here:
function get_my_db()
{
static $db;

if (!$db) {
$db = new mysqli('host', 'user', 'mypasswordhere');
mysqli_select_db($db, "mydatabase") or die ("no database");
}

return $db;
}
function user_exists($username) {
$db = get_my_db();
$username = $db->real_escape_string($username);
$query = $db->query("SELECT user_id FROM users WHERE username = '$username'");
$num_rows = $db->num_rows($query);
if ($num_rows == 1) { return true;
} else {
return false; } }
?>

and the function that calls it:
if (user_exists(joeybab3) === true){
echo "good job you finally did something right";
};

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest