10-13-2009, 03:59 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Posts: 39
Thanks: 9
|
Need some help with an error
Ok so I've been trying to teach myself php and am doing pretty good so far. I am making a little newsletter sign up for a site and it works fine, but I get an error. From what I understand this error should not allow the script to continue if it happens, but it doesn't and the script runs. The error is:
Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
And like I said the script runs fine, might not be the best way to do it, its a start. Here is what I have done.
Code:
if(isset($_POST['submit'])) {
//Set variables.
$firstname = strip_tags($_POST['firstname']);
$lastname = strip_tags($_POST['lastname']);
$email = $_POST['emailaddress'];
$accept = $_POST['accept'];
// Check for empty fields.
if (empty($firstname) || empty($lastname) || empty($emailaddress)) {
$message = "Please fill in all fields!";
} else {
$message = "All fields have been filled in!";
// If successful, continue sign up proccess.
// Check to see if info already exist.
$sql = "SELECT * FROM mailing_list WHERE firstname = '$firstname' AND lastname = '$lastname' AND email = '$emailaddress'";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result) != 0) {
$message = "This information already exist!";
} else {
// If information doesn't exist, add it.
$sql = "INSERT INTO mailing_list (id, firstname, lastname, email, accept) VALUES (null, '$firstname', '$lastname', '$emailaddress', '$accept')";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($result) != 0) {
$message = "Users information was not added!";
} else {
$message = "Users information was added successfully!";
}
}
}
} else {
}
How can I fix what is triggering this error or stop it from showing?
__________________
Trying to learn all I can about PHP. Teach me what you know...
|
|
|
|