Reputation: 4349
Hi i'm receiving the error below, i've double checked everything and don't know why its being displayed. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/namebob/public_html/site_reg/statlookup.php on line 6
<?php
include_once('common.php');
$cid = $_REQUEST['cid'];
$_elmID = $_REQUEST['elmID'];
$scan = mysql_query("SELECT `id`, `state` FROM `mast_state` WHERE `countryid` = $cid");
if(mysql_num_rows($scan)>0)
{
...
Upvotes: 0
Views: 560
Reputation: 3634
$scan = mysql_query("SELECT `id`, `state` FROM `mast_state` WHERE `countryid` = $cid");
$stock_num = '';
if($scan )
{
while($row=mysql_fetch_object($scan))
{
if($row->state)
$state = $row->state;
}
}
Upvotes: 1
Reputation:
Most probably your query is failing. Try:
if($scan) {
if(mysql_num_rows($scan) > 0) {
//...
}
} else {
trigger_error(mysql_error());
};
Upvotes: 1
Reputation: 1511
$scan = mysql_query("SELECT `id`, `state` FROM `mast_state` WHERE `countryid` = '".mysql_real_escape_string($cid)."'");
But really, use PDO.
$stm = $db->prepare("SELECT `id`, `state` FROM `mast_state` WHERE `countryid` = ?"); if( $stm && $stm->execute(array($cid)) ) { while( $data = $stm->fetch(PDO::FETCH_ASSOC) ) { } }
Upvotes: 1
Reputation: 60516
It's worth trying var_dump($scan)
, if you get something like null / false, that means the query fails. If that's the case, try echo mysql_error()
to check for any sql error (missing table etc)
Upvotes: 1