Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery is working but I get this error - Warning: mysql_numrows() expects parameter 1 to be resource, boolean given
    primarykey
    data
    text
    <p>I am trying to create a notification message when a new result is added to the database for certain members. I have 3 documents I am using for this, index.tpl, checkmsg.php and functions.php</p> <p><strong>In the index.tpl I have this code :</strong></p> <pre><code>&lt;script&gt; $(document).ready(function(){ var count = 0; setInterval(function() { $.post("checkmsg.php", { countOld: count }, function(data){ if(data == 0) { return; } else { count = data; alert("You have New Messages"); return; } }); }, 1000); }); &lt;/script&gt; </code></pre> <p><strong>In the checkmsg.php I have this:</strong></p> <pre><code>&lt;?php include("functions.php"); dbConnect(); $username = getUsernameByID($userid); if($username = 'None') { die(); } else{ $sql = "SELECT * FROM users WHERE username = $username AND msgs =&gt; 1"; $result = mysql_query($sql); echo $sql; if( !$result ) { // Kill SQL and return error } else { // We will be sending an Old Count via POST $numRows = mysql_num_rows($result); if( $numRows == $_POST['countOld'] ) { // No change echo '0'; } else echo $numRows; } } ?&gt; </code></pre> <p><strong>In functions.php I have:</strong></p> <pre><code>function getUsernameByID($id) { $query = 'SELECT username FROM users WHERE id = '.$id.' AND msgs = '.$GLOBALS['msgs']; $result = mysql_query($query); $num = mysql_numrows($result); // Line 61 if($num != 1) return "None"; else return mysql_result($result, 0); } </code></pre> <p>I added echo $sql; to checkmsgs.php to check if the query is working and it is as it returns this:</p> <pre><code>SELECT * FROM users WHERE username = None AND msgs =&gt; 1 </code></pre> <p>But above this there is an error:</p> <blockquote> <p>Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in functions.php on line 61</p> </blockquote> <p>When I try a simple query in checkmsgs.php like below, everything works including the notification on the index</p> <pre><code>SELECT * from users where msgs = 1; </code></pre> <p>But when I get this error the notification stops working even though the query is showing correctly.</p> <p>What can I do to fix this?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload