Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL works in phpMyAdmin but returns wrong number of rows in webpage script
    primarykey
    data
    text
    <p>I have a login scrip that previously appeared to work, but now is not working for some users, including some that previously worked.</p> <p>The SQL always works in phpMyAdmin, but on the webpage for some users it always returns zero rows. Here is the code where there is a problem:</p> <pre><code>$query_str = 'SELECT id, username, level_access, active FROM users WHERE username = "'; $query_str .= mysql_real_escape_string($uname).'"'; $query_str .= ' AND password = "'.mysql_real_escape_string($pwd).'"'; echo $query_str. "&lt;br/&gt;"; $result = mysql_query($query_str); $num_result = mysql_num_rows($result); echo $num_result. "&lt;br/&gt;"; </code></pre> <p>I spent considerable time testing any variations, and combinations that I could think of, I added back quotes, changed variable names, inserted other variables, simplified the expressions. Each change I tested the outputted query statement in phpMyAdmin. I added other users, deleted users and re-created them, I changed access levels and usernames.</p> <p>Always I got the same result, for some users the login always works for others it always returns no rows, even though they are returned in phpMyAdmin</p> <p>Finally I removed the where statement so that I created the following SQL statement:</p> <pre><code>$query_str = 'SELECT id, username, level_access, active FROM users'; </code></pre> <p>In my webpage this always returns 8 rows, no matter how many users there are. If there are 8, 9 or 10 users it return 8 rows. I deleted users so that there are less than 8 users, but there are still 8 rows returned to the webpage phpMyAdmin the correct number is returned each time.</p> <p>It seems clearly that the issue is not the code. So this is beyond my expertise. What could be causing this problem and how do I solve it?</p>
    singulars
    1. This table or related slice is empty.
    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