Jump to content

[SOLVED] PHP error


supermerc

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.