mysql to mysqli conversion

+2 Mitch Mullvain · November 26, 2014
I'm having a hard time trying to convert some of the code present in the PHP Login and Register tutorials.

I'm trying to convert some of the mysql statements to mysqli.

I understand most of the conversions (i.e. mysqli_query just adds a connection as a parameter). One function I'm not understanding fully is the mysqli_result function. I have never used this before, so I am not sure as to how it works. 

When I test out the code, I get an error such as:
Fatal error: Call to undefined function mysqli_result() in C:\xampp\htdocs\offstreams\core\functions\users.php on line 7

my code being:
function user_exists($username){
$username = sanitize($username);
$sql = "SELECT COUNT (`user_id`) FROM `users` WHERE `username` = '$username'";
$query = mysqli_query($conn, $sql);

// In the video this is "mysql_result(...)...)..." //
return (mysqli_result($query, 0) == 1) ? true : false;

just like in the video:

Could someone explain how to convert this code to fit mysqli?

Post a Reply


Oldest  Newest  Rating
0 Ricky singh · December 4, 2014
change your mysql_connect => mysqli_connect();
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.