Fatal error: Uncaught Error: Call to undefined function mysqli_result()

Helloo

i need to get a one value from a  table  and store it in a variable using this code  
$OwnerName= mysqli_result(mysqli_query($con,"SELECT Name FROM buyer WHERE usersId='$client_id'"),0);
but it con't work.

Please I need your helps!
NIYONSE SchaddyAsked:
Who is Participating?
 
Julian HansenCommented:
Rule #1 in programming - there are no shortcuts.
Don't do this
$OwnerName= mysqli_result(mysqli_query($con,"SELECT Name FROM buyer WHERE usersId='$client_id'"),0);

Open in new window

1. It is a nightmare to read
2. You have no control over the process if things go wrong

Personally I prefer the OOP version of the library - it is far more intuitive but we will work with the procedural version. Here is how I would do this

$query = "SELECT Name FROM buyer WHERE usersId='{$client_id}'"
$result = mysqli_query($con,$query)
if ($result) {
    $row = mysqli_fetch_object($result);
    echo "Name is {$row->Name}";
}
else {
   echo "Error: " . mysqli_error($con);
}

Open in new window

1
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Provide more context.

Likely you're calling mysqli_connect() from PHP.

So, first dump your phpinfo() output + ensure your hosting environment has install the PHP mysql extension.

Probably this extension is missing + will have to be installed, to clear your error.
0
 
Dave BaldwinFixer of ProblemsCommented:
I agree with Julian, I never combine functions like that.  Make them separate statements as he shows above.
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Poster has stopped posting, so appears Julian's answer is likely best.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.