I am getting this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myuser/public_html/saml/oc.php on line 35 Code (markup): Line 35 is shown below $username=$_SESSION['username']; $above = mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch = mysql_fetch_object($above); $oc_id=strip_tags($_GET['oc_id']); if (strip_tags($_GET['place']) == "we"){ $use="we_inv"; $a="we"; $query= "SELECT * FROM oc WHERE we_inv='$username' AND id='$oc_id'"; }elseif (strip_tags($_GET['place']) == "ee"){ $use="ee_inv"; $a="ee"; $query= "SELECT * FROM oc WHERE ee_inv='$username' AND id='$oc_id'"; }elseif (strip_tags($_GET['place']) == "driver"){ $use="driver_inv"; $a="driver"; $query= "SELECT * FROM oc WHERE driver_inv='$username' AND id='$oc_id'"; } $round=mysql_query($query); $check=mysql_num_rows($round); <----LINE 35 HERE if ($check != "0"){ mysql_query("UPDATE `oc` SET `$a`='$username' WHERE `id`='$oc_id'"); mysql_query("UPDATE `users` SET `oc`='1' WHERE `username`='$username'"); echo "<SCRIPT LANGUAGE='JavaScript'> window.location='oc.php'; </script>"; } PHP:
There may be an error in the query thats why $round isn't a valid resource try editing line 34 to: $round=mysql_query($query) or die(mysql_error()); PHP: to see if there is an error. Cheers!
Yes thanks. I got the following 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 'Resource id #4' at line 1 Code (markup):
It's likely caused by one of your user submitted variables not being set/defined, theirfore I've added a few if statements to check - also improved your code slightly (to make it more readable)...use the following code, and let me know how that goes (also quote any errors - if any; within your next post): <?php error_reporting(E_ALL); if (!isset($_SESSON['username'])) { echo 'You must be logged in!'; } elseif (!isset($_GET['oc_id'])) { echo 'oc_id is not set!'; } elseif (!isset($_GET['place'])) { echo 'place is not set!'; } else { $username = $_SESSION['username']; $above = mysql_query("SELECT * FROM users WHERE username = '{$username}'"); $fetch = mysql_fetch_object($above); $oc_id = intval($_GET['oc_id']); if ($_GET['place'] == 'we') { $use = 'we_inv'; $a = 'we'; $query = "SELECT * FROM oc WHERE we_inv = '{$username}' AND id = '{$oc_id}'"; } elseif ($_GET['place'] == 'ee') { $use = 'ee_inv'; $a = 'ee'; $query = "SELECT * FROM oc WHERE ee_inv = '{$username}' AND id = '{$oc_id}'"; } elseif ($_GET['place'] == 'driver') { $use = 'driver_inv'; $a = 'driver'; $query = "SELECT * FROM oc WHERE driver_inv = '{$username}' AND id = '{$oc_id}'"; } $round = mysql_query($query); $check = mysql_num_rows($round); if ($check != 0): mysql_query("UPDATE oc SET {$a} = '{$username}' WHERE id = '{$oc_id}'"); mysql_query("UPDATE users SET oc = '1' WHERE username = '{$username}'"); ?> <script language='JavaScript'> window.location='oc.php'; </script> <?php endif; } ?> PHP:
That didn't work but I noticed that I used $query twice, so i changed it to $getit and now get the error below Query was empty Code (markup):
Erm that isn't an error? (or atleast from my entire time doing PHP havn't ever come accross that :/) Your current code sets a variable $query based on the $_GET...and then later on in the script you use that $query. So if those $_GET's are not set you'll get an error as their is no query to execute. The same applies for the $_SESSION['username'] Theirfore: - make sure all variables exist/are set so it can query properly. - make sure all column names and table names are exist!