Jump to content

Error with Mysql query


don4of4

Recommended Posts

I have this error that I can't figure out...  Any help is appreciated. $1 reward offered for a solution.

 

The error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... on line 16

 

The code:

if(isset($_POST['Submit'])) 
{
$fname = strtoupper(mysql_real_escape_string(trim($_POST['fname'])));
$mname = strtoupper(mysql_real_escape_string(trim($_POST['mname'])));
$lname = strtoupper(mysql_real_escape_string(trim($_POST['lname'])));
$sname = strtoupper(mysql_real_escape_string(trim($_POST['sname'])));
if ($fname == null or $mname == null or $lname == null) {$final_report = "ERROR: Enter all parts of your name!";} else {
//validate name
$formatname = trim($lname.', '.$fname.' '.$mname.'. '.$sname);
$check_fname = mysql_query("SELECT * FROM `roster` WHERE `name`='$formatname'") or die(mysql_error());   
if (mysql_num_rows($check_members) == 0) {$final_report = "We have no record of your name in our server.  Please check your spelling.";}
//end


}}

 

The command    SELECT * FROM `roster` WHERE `name`='NAME HERE'    works fine when executed directly on the SQL server. 

Link to comment
https://forums.phpfreaks.com/topic/205139-error-with-mysql-query/
Share on other sites

The return status of the mysql_query() are in one variable, but you're using a different variable for the mysql_num_rows() function:

<?php
$check_fname = mysql_query("SELECT * FROM `roster` WHERE `name`='$formatname'") or die(mysql_error());   
if (mysql_num_rows($check_members) == 0) {$final_report = "We have no record of your name in our server.  Please check your spelling.";}
?>

Make them the same

<?php
        $check_fname = mysql_query("SELECT * FROM `roster` WHERE `name`='$formatname'") or die(mysql_error());   
if (mysql_num_rows($check_fname) == 0) {$final_report = "We have no record of your name in our server.  Please check your spelling.";}
?>

 

Ken

 

Please check

 

$check_fname = mysql_query("SELECT * FROM `roster` WHERE `name`='$formatname'") or die(mysql_error()); 

 

//$check_fname contains the result set.But in function -mysql_num_rows you are referring to '$check_members'

 

mysql_num_rows($check_members)

 

Kindly try,  mysql_num_rows($check_fname) ..

 

Let us know if it works.

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.