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. Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/ 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. Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767864 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]); Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767869 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. Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767871 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(). Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767873 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. Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767874 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']??? Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767878 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); Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767880 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']); Link to comment https://forums.phpfreaks.com/topic/146264-solved-php-error/#findComment-767884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.