Re: What am I doing wrong here?

From: Date: Tue, 26 Dec 2000 01:15:05 +0000
Subject: Re: What am I doing wrong here?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-31805@lists.php.net to get a copy of this message
At 05:00 PM 12/25/2000 -0800, Lynn Siprelle wrote: try making the field that holds the test name "unique" in the mysql table that you are using. ~kurth
Hi guys-- I'm going through a couple of tutorials on user validation/tracking, and I come up with the same kind of problem over and over again. (Background: MySQL, PHP4, FreeBSD, Apache w/mod_php, full permissions to do whatever I'd like pretty much. Have verified that PHP and MySQL are working fine otherwise. I am a newbie, however.) Here's the problem: Whenever I'm trying to verify whether someone has already entered a user name into the database, I get some kind of error. Here's an example taken from a devshed tutorial of a script that gives me this trouble (and I do have the username, password and database correctly entered), using an html form page to submit a first name and a last name into the database via this script: <?php mysql_connect (localhost, myusername, mypwd); mysql_select_db (mydb); $result = mysql_query("SELECT * FROM users WHERE first_name=$first_name AND last_name=$last_name"); if (mysql_num_rows($result) == 1){ print "Sorry, someone has already entered your name into the database."; } else { mysql_query ("INSERT INTO users (first_name, last_name) VALUES ('$first_name', '$last_name')"); print ($first_name); print (" "); print ($last_name); print (" "); print ("Thanks for submitting your name."); } ?> This particular version of trying for verification produces the error Warning: Supplied argument is not a valid MySQL result resource in /path/to/submitform.php on line 11 And then it goes ahead and executes the "else" statement, even if the name already exists in the database; when I go into MySQL and check, there are now two entries of my test name. I have tried at least one other tutorial on this with similar results (a parse error instead of a "not a valid MySQL result resource" error) and have dug through the mysql functions in the manual trying to see what I'm doing wrong (or at least figure out why I can't get a pre-scripted tutorial to run). I should add that I believe the tutorials I'm working through are geared to php3 if I'm not mistaken, but I thought php4 was backwards compatible, nu? I should also add that the script executes fine WITHOUT the validation section, neatly placing the name into the table and echoing back a polite thank-you. Ideas? I'm a newbie, so it very well may be something stoopid I'm doing; be gentle but firm. :) Lynn -- Siprelle & Associates: Distinctive Web Design Since 1994 Lynn Siprelle, President: Newest Associate Josie born 9/9/97 Business: lynn@siprelle com | Personal: lynsa@siprelle.com Portfolio: http://www.siprelle.com/ | TNH: http://www.newhomemaker.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
Kurth Bemis - Network/Systems Administrator, USAExpress.net/Ozone Computer People disagree with me. I just ignore them.
        -- Linus Torvalds, regarding the use of C++ for the Linux kernel
kurth@usaexpress.net | http://www.usaexpress.net/kurth PGP key available - http://www.usaexpress.net/kurth/pgp Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net (http://www.distributed.net)

« previous php.general (#31805) next »