TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-13-2009, 02:59 PM   #1 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default 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...
code_junkie is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Parse error: parse error,syntex error unexpected ',' expectingT_STRING in my code tech Absolute Beginners 13 01-29-2013 10:00 AM
cant work this error out talonos Absolute Beginners 11 07-13-2009 11:03 AM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
an error makes me crazy nuts !!!!!!! webtuto Absolute Beginners 1 02-27-2008 10:31 AM


All times are GMT. The time now is 09:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design