-2

I am getting this error while changing from mysql_result to mysqli_result

function f_exists($f_uname) {
     $f_uname = sanitize($f_uname);
     $conn = @mysqli_connect('localhost','root','','swift') or die($connect_error);
     $query = mysqli_query($conn,"SELECT COUNT(`f_id`) FROM `flight_users` WHERE `f_uname`= '$f_uname'") or die(mysqli_error($conn));


    //here is the problem
    return (mysql_result($query, 0) == 1) ? true : false; 

}

rbr94
  • 2,227
  • 3
  • 23
  • 39

1 Answers1

1

Do not mix mysql_* and mysqli_*. Furthermore you cannot use mysql_result in the way you use it with mysql_*. Just replace this

return (mysql_result($query, 0) == 1) ? true : false; 

with the following:

if ($query && mysqli_num_rows($query) == 1) {  
    $row = mysqli_fetch_assoc()['count_val'];  
}

Therefore you need to use an alias for your count value in your statement, which you should always do: SELECT COUNT(f_id) as count_val ...

See this topic for more information about an equivalent to the mysql_result in mysql_*: MySQLi equivalent of mysql_result()?

Community
  • 1
  • 1
rbr94
  • 2,227
  • 3
  • 23
  • 39