Re: What am I doing wrong here?
| From: | Toby Butzon | Date: | Tue, 26 Dec 2000 01:13:22 +0000 |
| Subject: | Re: What am I doing wrong here? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31807@lists.php.net to get a copy of this message | ||
Try this and see what happens:
$result = mysql_query("SELECT * FROM users WHERE first_name=$first_name AND
last_name=$last_name") or die("Error on " . __LINE__ . " of " . __FILE__ .
": " . mysql_error());
Typically if it doesn't see $result as a valid resource it means your query
failed; if that's the case, adding the or die(...) to it will tell you why
it's failing ;)
Toby Butzon
[ criticism spurs improvement ]
----- Original Message -----
From: "Lynn Siprelle" <lynn@siprelle.com>
To: <php-general@lists.php.net>
Sent: Monday, December 25, 2000 8:00 PM
Subject: [PHP] What am I doing wrong here?
: 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/
:
: --
: 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
:
: