Jump to content

mysql_num_rows() error?


Mr Chris

Recommended Posts

Hello,

 

Say I wanted to check a record in my database before submitting some data to that database via a form I thought i'd do it like so:

 

  $duplicates = mysql_num_rows(mysql_query("SELECT name FROM table WHERE fullname = $full_name"));
   if ($duplicates > 0) {  
      $msg[] = "Error already exisits";
   }

 

However I get the message:

 

mysql_num_rows(): supplied argument is not a valid MySQL result resource

 

I thought that would work?

 

Any idea as to why thanks?

Link to comment
https://forums.phpfreaks.com/topic/182678-mysql_num_rows-error/
Share on other sites

its best to use $row and mysql_fetch_array().

 

That way, it will print the chosen table value

 

$query = "SELECT * FROM `$tbl`"; 

// store the record of the "$tbl" table into $row
$result = mysql_query($query) or die(mysql_error());

echo "<table id=\"mytbl\" name=\"mytbl\" border='1'>\n"
."<tr><th>ID</th> <th>IP that submitted this data</th> <th>Hostname of the IP that submitted the data</th> <th>First Name</th> <th>Last Name</th> <th>Shipping Address</th> <th>City</th> <th>State/Province</th> <th>Zipcode</th> <th>Paid</th> <th>Date payment was received</th> <th>Time payment was received</th> <th>Item Purchased</th> <th>Amount of item(s) purchased</th> <th>Date data was inserted</th> <th>Time data was inserted</th></tr>\n"
."<tr>\n";
while($row = mysql_fetch_array($result)){
$tbldata = "<td align=\"center\">\n"
.$row['id']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['ipsubmit']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['hostsubt']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['firstname']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['lastname']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['shipaddress']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['city']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['stateprovince']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['zipcode']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['paid']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['datepaid']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['timepaid']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['itempurchased']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['amountpurchased']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['dateinserted']."<br>\n"
."</td>\n"
."<td align=\"center\">\n"
.$row['timeinserted']."<br>\n"
."</td>\n"
."</tr>\n";
echo $tbldata;
}
echo "</table>\n";

 

Hope that helps u ^^

 

Good luck! ^^

 

Shadow~

Link to comment
https://forums.phpfreaks.com/topic/182678-mysql_num_rows-error/#findComment-964165
Share on other sites

The error from mysql_num_rows is because there was a syntax error in your query string. Probably because your fullname field isn't numeric so it needs quotes around the criteria:

"SELECT name FROM table WHERE fullname = '$full_name'"

 

It always helps to add "or die()" to your query so you know if it is actually working.

mysql_query($query) or die(mysql_error() . " Query: " . $query);

Link to comment
https://forums.phpfreaks.com/topic/182678-mysql_num_rows-error/#findComment-964172
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.