Jump to content

Mysqli_num_rows


Xtremer360

Recommended Posts

I keep getting this error because of my coding and I'm not sure why all I know is it has to do wiht the query itself.

 

<b>Warning</b>:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in <b>C:\wamp\www\E-Fed Manager  (localhost)\processes\template.php</b> on line <b>37</b><br />

 

 

$query = "SELECT * FROM `templates` WHERE `templatename` = $templatename";
    $result = mysqli_query ( $dbc, $query ); // Run The Query
    $rows = mysqli_num_rows($result);

Link to comment
Share on other sites

$query = "SELECT * FROM `templates` WHERE `templatename` = $templatename";
if( $result = mysqli_query ( $dbc, $query ) ) { // Run The Query
    $rows = mysqli_num_rows($result);
} else {
     echo "<br>Query: $query<br>Produced error:" . mysqli_error($dbc) . '<br>';
}

Link to comment
Share on other sites

<br>Query: SELECT * FROM `templates` WHERE `templatename` = Testing Template 2<br>Produced error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Template 2' at line 1<br><br />

<b>Notice</b>:  Undefined variable: rows in <b>C:\wamp\www\E-Fed Manager  (localhost)\processes\template.php</b> on line <b>42</b><br />

 

Which means my only issue is the rows variable not being defined, correct?

 

Link to comment
Share on other sites

No, it actually looks like the cause of the query failure is the lack of quotes around $templatename in the query string. The undefined variable $rows warning is a probably a result of the first error, unless there's another query further along in the script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.