Jump to content

Archived

This topic is now archived and is closed to further replies.

network23

Why does email address apparently crash MySQL???

Recommended Posts

newbie here, but strange situation.

 

Here\'s what I want to do. My page takes a form and enters information into the database, including an email address. I want to get the primary key of the user with that email address that I just entered.

 

So here\'s my code...

 

$sql = \\\"INSERT INTO user SET

 firstname=\'$firstname\',

 lastname=\'$lastname\',

 email=\'$email\',

 phone=\'$phone\',

 agency=\'$agency\',

 password=\'$password\'\\\";

if (@mysql_query($sql)) {

echo(\\\"<p>You are registered!</p>\\\");

} else {

echo(\\\"<p>Error adding class: \\\" . mysql_error() . \\\"</p>\\\");

}

 

// get userid of new member

$sqlread = \\\"SELECT userid FROM user WHERE email = \'$email\'\\\";

 

$readresult = mysql_query($sqlread);

if (!$readresult) {

echo( \\\"<p>Error performing query: \\\" . mysql_error() . \\\"</p>\\\" );

exit();

}

 

and this is what I get when I run it...

 

You are registered!

Error performing query: \\\" . mysql_error() . \\\"

 

\\\" ); exit(); } echo \\\"\\\"; // Display all the classes in a table // echo \\\"n\\\"; while ( $row = mysql_fetch_array($readresult) ) { $classid = $row[\\\"classid\\\"]; $title = $row[\\\"title\\\"]; $date = $row[\\\"date\\\"]; $fee = $row[\\\"fee\\\"]; $feedue = $row[\\\"feedue\\\"]; $sizelimit = $row[\\\"sizelimit\\\"];

 

...etcetra...it just dumps to PHP code.

 

How can I check using WHERE with a PHP variable? Even when I replace the $email with a real email address it still does the same thing.

Share this post


Link to post
Share on other sites

Arg, I can\'t edit my last post :[ My comp. has a problem with the cookies on this site :[

 

Anyway, to answer your question properly (I obviously didn\'t read it right)... you should be able to check the email variable that way o.O; I don\'t know if you are planning to have a HUGE website thing with tonnes of members, but if not, I have a different suggestion. Try getting the userid of the last member to sign up.

 

That might be a problem if you are planning on this very popular website, because more than one person sould join at the same time, and mess things up :[ But if you are just trying to have a moderate site, try this:

 

$sql = mysql_query("INSERT INTO table (column) VALUES (\'$myvalue\')") or die (mysql_error()); 



$insert_id = mysql_insert_id(); 

 

Code taken from PHPFreak\'s QuickCode library. The variable $insert_id should now hold the newest id in the database. Hope that helps!

Share this post


Link to post
Share on other sites

Thank you! That worked!

 

But I\'m still going to have to read in the email address at some point!

 

(Turns out the \"mysql crashing\" was some incomplete code further down the page)

 

Here\'s my SQL statement...

 

$sqlread = \\\"SELECT userid, firstname, lastname, email, phone, agency, password FROM user WHERE (email = $lemail) AND (password = $lpassword)\\\";

 

Why do I get this when I run it?...

 

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near \'@mail.state.il.us) AND (password = 55555)\' at line 1

 

It only appears to do this when I try to include a real email address in the WHERE statement. I\'m assuming it has something to do with \'@\', but I don\'t know how to fix it.

Share this post


Link to post
Share on other sites

Try this

 

$sqlread = "SELECT userid, firstname, lastname, email, phone, agency, password FROM user WHERE email = \'$lemail\' AND password = \'$lpassword\'"; 

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.