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
https://forums.phpfreaks.com/topic/224273-mysqli_num_rows/
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
https://forums.phpfreaks.com/topic/224273-mysqli_num_rows/#findComment-1158724
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
https://forums.phpfreaks.com/topic/224273-mysqli_num_rows/#findComment-1158726
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
https://forums.phpfreaks.com/topic/224273-mysqli_num_rows/#findComment-1158731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.