supermerc Posted February 21, 2009 Share Posted February 21, 2009 Hey Im getting this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9337486/public_html/vault.php on line 102 This is line 100 to 105 <?php $st = "SELECT * FROM aps WHERE name = $name"; $qr = mysql_query($st); $selaps = mysql_num_rows($qr); $s = "SELECT * FROM items WHERE name = $match[1]"; $r = mysql_query($s); $selitem = mysql_num_rows($r); ?> line 102 is $selaps = mysql_num_rows($qr); Thanks for helping. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 21, 2009 Share Posted February 21, 2009 No doubt $name and $match[1] are strings - as such you need quotes around them: $st = "SELECT * FROM aps WHERE name = '$name'"; In future, you should try debugging your queries. Do something like this: $sql = "SELECT * FROM..." $result = mysql_query($sql) or trigger_error(mysql_error().'<br />Query: '.$sql,E_USER_ERROR); That way you'll actually be able to find out what went wrong. Quote Link to comment Share on other sites More sharing options...
supermerc Posted February 21, 2009 Author Share Posted February 21, 2009 Thanks it works now, just one thing Im trying to grab something from one of my table in database then add a number and it doesnt seem to be working, this is what I have: $newaps = ($selaps[aps] + $selitem[dvalue]); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 21, 2009 Share Posted February 21, 2009 You might want to define 'not working'. What happens? What doesn't happen? In any case, you should be quoting those strings being uses as array indexes (e.g. $selaps['aps']). An unquoted string is a constant. Though php guesses that you meant to use a string if the constant is undefined, it may cause you problems depending on your error_reporting level. And it's bad practice. Quote Link to comment Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 mysql_num_rows only returns the number of rows returned by the query, you want to be using mysql_fetch_assoc() or mysql_fetch_array(). Quote Link to comment Share on other sites More sharing options...
supermerc Posted February 21, 2009 Author Share Posted February 21, 2009 well after I have a query to update it: $final = mysql_query("UPDATE aps SET aps= '$newaps' WHERE name = '$name'") or die(mysql_error()); And when i check in database its still 0 when it shouldnt be. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 21, 2009 Share Posted February 21, 2009 Unless you have some code that is setting $selaps['aps'] and $selitem['dvalue'], they don't exist. The code you have posted so far only sets $selaps and $selitem and it only sets them to the number of rows in the result sets of the two queries you posted. Are you developing and debugging php code on a system with error_reporting set to E_ALL so that php would be telling you of nonexistent variables like $selaps['aps'] and $selitem['dvalue']??? Quote Link to comment Share on other sites More sharing options...
supermerc Posted February 21, 2009 Author Share Posted February 21, 2009 I dont think so and I dont understand why they are non existing Im defining them here $st = "SELECT * FROM aps WHERE name = '$name'"; $qr = mysql_query($st); $selaps = mysql_num_rows($qr); $s = "SELECT * FROM items WHERE name = '$match[1]'"; $r = mysql_query($s); $selitem = mysql_num_rows($r); Quote Link to comment Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 As I said, mysql_num_rows does not fetch data, so $selitem and $selaps will just be the number of rows, to get some data use mysql_fetch_array(); like: $st = "SELECT * FROM aps WHERE name = '$name'"; $qr = mysql_query($st); $selaps = mysql_fetch_array($qr); $s = "SELECT * FROM items WHERE name = '$match[1]'"; $r = mysql_query($s); $selitem = mysql_fetch_array($r); $newaps = ($selaps['aps']+ $selitem['dvalue']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.