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='[email protected]'' 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. Link to comment https://forums.phpfreaks.com/topic/172214-select-from-users-where-email-123abccom/ Share on other sites More sharing options...
waynew 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. Link to comment https://forums.phpfreaks.com/topic/172214-select-from-users-where-email-123abccom/#findComment-908007 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. Link to comment https://forums.phpfreaks.com/topic/172214-select-from-users-where-email-123abccom/#findComment-908048 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... Link to comment https://forums.phpfreaks.com/topic/172214-select-from-users-where-email-123abccom/#findComment-908079 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. Link to comment https://forums.phpfreaks.com/topic/172214-select-from-users-where-email-123abccom/#findComment-909410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.