What am I doing wrong here?
| From: | Lynn Siprelle | Date: | Tue, 26 Dec 2000 01:00:54 +0000 |
| Subject: | What am I doing wrong here? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31804@lists.php.net to get a copy of this message | ||
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:
<html>
<body>
<?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 ("<p>");
print ("Thanks for submitting your name.");
}
?>
</body>
</html>
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/