don4of4 Posted June 18, 2010 Share Posted June 18, 2010 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 More sharing options...
kenrbnsn Posted June 18, 2010 Share Posted June 18, 2010 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 Link to comment https://forums.phpfreaks.com/topic/205139-error-with-mysql-query/#findComment-1073766 Share on other sites More sharing options...
priti Posted June 18, 2010 Share Posted June 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/205139-error-with-mysql-query/#findComment-1073768 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.