Celeritas
Celeritas

Reputation: 15043

Determining if no rows are returned from a prepared statment

I'm implementing prepared statements on my already working mysqli queries. I'm having trouble with a line if(mysqli_num_rows($result) == 0) as it's now a string instead of a mysqli_result.

if($nameAvailableStmt = mysqli_prepare($link, 'SELECT name FROM usetbl1 WHERE name=? LIMIT 1'))
{
    mysqli_stmt_bind_param($nameAvailableStmt, "s", $_POST['dangerous']);
    mysqli_stmt_execute($nameAvailableStmt);
    mysqli_stmt_bind_result($nameAvailableStmt, $result);
    mysqli_stmt_fetch($nameAvailableStmt);
}
if(mysqli_num_rows($result) == 0)

Upvotes: 2

Views: 106

Answers (1)

Barmar
Barmar

Reputation: 780889

It should be:

mysqli_stmt_store_result($nameAvailableStmt);
if(mysqli_stmt_num_rows($nameAvailableStmt) == 0)

See the Documentation

Upvotes: 3

Related Questions