kittrellbj Posted August 28, 2009 Share Posted August 28, 2009 What I am trying to do is see if a email address exists in the database. So, the database has field 'email' in the 'users' table. I keep getting an error: "Couldn't connect. 2You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' WHERE email='123@123.com'' at line 1" The query looks like this: $usertable = "users"; $regemail = $_POST['email']; $reg_query = "SELECT * FROM '$usertable' WHERE email='$regemail'"; $reg_result = mysql_query($reg_query) or die("Couldn't connect. 2" . mysql_error()); Any ideas? I've tried searching about a bit for an answer to this, but I don't quite see where the problem is. It's not a complicated query, and the one right above it runs just fine (at least, it hasn't shot back any error code). So, I'm thinking it has something to do with an @ symbol in a WHERE clause, but not sure how to repair it. Quote Link to comment Share on other sites More sharing options...
waynewex Posted August 28, 2009 Share Posted August 28, 2009 $reg_query = "SELECT * FROM $usertable WHERE email='$regemail'"; Use that. You had placed single quotes around the tablename, which isn't allowed. Use double quotes when using strings only. Quote Link to comment Share on other sites More sharing options...
kittrellbj Posted August 28, 2009 Author Share Posted August 28, 2009 Oh, wow. I didn't even realize that was not allowed. Thanks. Sometimes the simplest things drive us absolutely nuts. Quote Link to comment Share on other sites More sharing options...
bacarudaguy Posted August 28, 2009 Share Posted August 28, 2009 or die("Couldn't connect. 2" . mysql_error()); I'm curious why you have the number 2 in there... Quote Link to comment Share on other sites More sharing options...
kittrellbj Posted August 30, 2009 Author Share Posted August 30, 2009 or die("Couldn't connect. 2" . mysql_error()); I'm curious why you have the number 2 in there... It's an internal coding system that I use in order to track my errors a little closer. Each line that outputs an error shoots out an error code (in this case, "2") so that I know where it is coming from specifically in the program. Edit: I know it is kinda redundant, but it helps me. 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.