network23 Posted November 19, 2003 Share Posted November 19, 2003 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. Quote Link to comment Share on other sites More sharing options...
triphis Posted November 20, 2003 Share Posted November 20, 2003 IGNORE THIS POST, LOOK DOWN Quote Link to comment Share on other sites More sharing options...
triphis Posted November 20, 2003 Share Posted November 20, 2003 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! Quote Link to comment Share on other sites More sharing options...
network23 Posted November 20, 2003 Author Share Posted November 20, 2003 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. Quote Link to comment Share on other sites More sharing options...
shivabharat Posted November 20, 2003 Share Posted November 20, 2003 Try this $sqlread = "SELECT userid, firstname, lastname, email, phone, agency, password FROM user WHERE email = \'$lemail\' AND password = \'$lpassword\'"; Quote Link to comment Share on other sites More sharing options...
network23 Posted November 20, 2003 Author Share Posted November 20, 2003 Stupid me! :x Yes, that was it. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.