Click to See Complete Forum and Search --> : [RESOLVED] Sql Error php bug
kproc
07-27-2006, 09:02 PM
below is code that I have been staring at for hour and I cannot find the issue
I get this error message
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\MyServer\xampp\htdocs\NewStuff\familypages\CodeAboutMe.php on line 39
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\MyServer\xampp\htdocs\NewStuff\familypages\CodeAboutMe.php on line 40
when I remove this section of code all works well
/* checking and ensure that the has not been added */
$sql_mom_check = mysql_query("SELECT momFirstName, momLastName, momDob
FROM aboutMe WHERE momLastName='$momLastName' AND momFistName='$momLastName' AND momDob='$momDob'");
$sql_dad_check = mysql_query("SELECT dadFirstName, dadLastName, dadDob
FROM aboutMe WHERE dadLastName='$dadLastName' AND dadFistName='$dadLastName' AND dadDob='$dadDob' ");
$mom_check = mysql_num_rows($sql_mom_check);
$dad_check = mysql_num_rows($sql_dad_check);
if(($mom_check > 0) || ($dad_check > 0)){
echo "Please fix the following errors: <br />";
if($mom_check > 0){
echo "<strong>Your email address has already been used by another member
in our database. Please submit a different Email address!<br />";
unset($momFirstName);
}
if($dad_check > 0){
echo "The username you have selected has already been used.
Please choose a different Username!<br />";
unset($dadFirstName);
}
include 'RegisterPage.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
NogDog
07-27-2006, 09:46 PM
Change your mysql_query lines as follows to help you find out why they failed (that's what those error messages are ultimately telling you):
$query1 = "SELECT momFirstName, momLastName, momDob
FROM aboutMe WHERE momLastName='$momLastName' AND momFistName='$momLastName' AND momDob='$momDob'";
$sql_mom_check = mysql_query($query1) or
die("QUERY 1 FAILED: $query1 - " . mysql_error());
$query2 = "SELECT dadFirstName, dadLastName, dadDob
FROM aboutMe WHERE dadLastName='$dadLastName' AND dadFistName='$dadLastName' AND dadDob='$dadDob' ";
$sql_dad_check = mysql_query($query2) or
die("QUERY 2 FAILED: $query2 - " . mysql_error());
I noticed that in both queries you used the LastName value from the form input to compare with both the first and last name columns in the table, but that alone should not be causing the error. My suspicion is that the PHP variables you are using in the queries are not populated, possibly because register_globals is (correctly) not turned on, so you need to use the relevant values from the $_POST array (or $_GET array if you used the get method for your form).
kproc
07-27-2006, 09:56 PM
I madwe changes recomended above and get the following message
Query failed: Resource id #4
kproc
07-27-2006, 10:00 PM
I tested my variables to make sure values are being assigned and all is well. i get I know get the error message I posted above. not shure what this means
kproc
07-28-2006, 08:05 AM
HI, I'm having a hard time finding information about the error message I'm getting "Query failed Resource id#4"
Does this message point me to some place in my code
aussie girl
07-28-2006, 08:15 AM
Well here's one problem....you can't do a search on momFirstName with $momLastName variable.. and is that suppose to be momFistName??
$query1 = "SELECT momFirstName, momLastName, momDob
FROM aboutMe WHERE momLastName='$momLastName' AND momFistName='$momLastName' AND momDob='$momDob'";
chazzy
07-28-2006, 08:33 AM
I madwe changes recomended above and get the following message
Query failed: Resource id #4
Show the code then.
kproc
07-28-2006, 09:45 AM
Below is the complete code
error Message: Query 1 FAILED: Resource id #4 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1
NOTE: When I delete the code for Query1 the same message shows up for query2.
<? session_start(); // Start Session?>
<?
include 'db.php';
// Define post fields into simple variables
$momFirstName = $_POST['momFirstName'];
$momLastName = $_POST['momLastName'];
$maddenName = $_POST['maddenName'];
$momDob = $_POST['momDob'];
$dadFirstName = $_POST['dadFirstName'];
$dadLastName = $_POST['dadLastName'];
$dadDob = $_POST['dadDob'];
$anniversaryDate = $_POST['anniversaryDate'];
$username = $_SESSION['username'];
//****************************************************************************************
$momFirstName = stripslashes($momFirstName);
$momLastNamee = stripslashes($momLastName);
$momDob = stripslashes($momDob);
$dadFirstName = stripslashes($dadFirstName);
$dadLastName = stripslashes($momLastName);
$dadDob = stripslashes($dadDob);
$anniversaryDate = stripslashes($anniversaryDate);
$maddenName = stripslashes($maddenName);
/* checking and ensure that the has not been added */
$query1 = mysql_query("SELECT momfirstname, momlastname, momdob
FROM aboutMe WHERE momlastname = '$momlastname' AND momfirstname = '$momfirstname'
AND momdob = '$momdob'");
$sql_mom_check = mysql_query($query1) or die("Query 1 FAILED: $query1 - ".mysql_error());
$query2 = mysql_query("SELECT dadfirstname, dadlastname, daddob
FROM aboutMe WHERE dadlastname = '$dadlastname' AND dadfirstname = '$dadfirstname'
AND daddob = '$daddob'");
$sql_dad_check = mysql_query($query2) or die("Query 2 FAILED: $query2 - ".mysql_error());
$mom_check = mysql_num_rows($sql_mom_check);
$dad_check = mysql_num_rows($sql_dad_check);
if(($mom_check > 0) || ($dad_check > 0)){
if($mom_check > 0){
echo "It looks Like someone has entered you mom's information<br />";
unset($momFirstName);
}
if($dad_check > 0){
echo "It looks like someone has enetered your dad's inforamtion!<br />";
unset($dadFirstName);
}
include 'aboutMe.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO aboutMe (momFirstName,
momLastName, momDob, dadFirstName, dadLastName, dadDob, anniversaryDate, username)
VALUES('$momFirstName', '$momLastName', '$momDob', '$dadFirstName', '$dadLastName', '$dadDob''$anniversaryDate', '$maddenName', '$username')")
or die (mysql_error());
if(!$sql){
}
$msg .='<div style="width:325px" id= "formmessage">';
$msg .= 'information has been added.';
$msg .= '</div>';
include 'loginhome.php';
?>
chazzy
07-28-2006, 10:02 AM
code like this should read:
$query1 = "SELECT momfirstname, momlastname, momdob
FROM aboutMe WHERE momlastname = '$momlastname' AND momfirstname = '$momfirstname'
AND momdob = '$momdob'"
$sql_mom_check = mysql_query($query1) or die("Query 1 FAILED: $query1 - ".mysql_error());
Basically you issued the query, then you tried to issue the query against the resource, can't do that. You need to udpate all of your blocks like that.
kproc
07-28-2006, 10:13 AM
thank you for the help, all is fixed. Silly mistake.