Jump to content

Why does email address apparently crash MySQL???


network23

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.

Link to comment
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!

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.