Jump to content


Photo

Why does email address apparently crash MySQL???


  • Please log in to reply
5 replies to this topic

#1 network23

network23
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 November 2003 - 11:32 PM

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.

#2 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 November 2003 - 03:26 AM

IGNORE THIS POST, LOOK DOWN
Xac Attack

#3 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 20 November 2003 - 03:38 AM

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!
Xac Attack

#4 network23

network23
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 November 2003 - 05:39 PM

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.

#5 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 20 November 2003 - 06:03 PM

Try this

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

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#6 network23

network23
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 November 2003 - 06:22 PM

Stupid me! :x

Yes, that was it. Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users