EPCtech Posted July 29, 2008 Share Posted July 29, 2008 Hello, My website, on the register page, says that my MySQL syntax to insert a member into the database is incorrect. Is there anything wrong with this? (P.S. - All variables exist) mysql_query("INSERT INTO login(username, password, email)VALUES(".$username.",".$password.",".$email) or die(mysql_error()); I don't get it. Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/ Share on other sites More sharing options...
mjedman1 Posted July 29, 2008 Share Posted July 29, 2008 The query was missing some chars at the end. mysql_query("INSERT INTO login(username, password, email)VALUES(".$username.",".$password.",".$email.")") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603053 Share on other sites More sharing options...
gabarab Posted July 29, 2008 Share Posted July 29, 2008 try this: mysql_query("INSERT INTO login (username, password, email) VALUES('$username','$password','$email')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603055 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 String data must be enclosed in single-quotes so that mysql knows they are strings and not identifiers. Edit: gabarab's is correct, but it is missing a closing " and ) on the end of the mysql_query() statement. Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603057 Share on other sites More sharing options...
revraz Posted July 29, 2008 Share Posted July 29, 2008 You want single quotes and no periods around your variables. Posting the error would help catch it also. mysql_query("INSERT INTO login (username, password, email)VALUES('$username', '$password', '$email'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603058 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 That one is missing a closing ) for the VALUES (...) clause. Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603060 Share on other sites More sharing options...
EPCtech Posted July 29, 2008 Author Share Posted July 29, 2008 Hi, Actually, "mjedman1" did it correctly. Thanks, my system now works! Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603062 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 Only if the contents in the variables contain single-quotes as well. Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603066 Share on other sites More sharing options...
EPCtech Posted July 29, 2008 Author Share Posted July 29, 2008 Hello, Now I have another problem. When I try making it so it adds the user group, it has the same error: mysql_query("INSERT INTO login(username, password, email, group)VALUES('".$username."','".$password."','".$email."','".$group."')") or die(mysql_error()); Any help? Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603154 Share on other sites More sharing options...
PFMaBiSmAd Posted July 30, 2008 Share Posted July 30, 2008 If you were to post the error messages you are getting, you would get a more direct and quicker solution because the error points to the place in the query where the problem is. group is a reserved keyword. Either change the column name to something else or enclose it in back-ticks. Link to comment https://forums.phpfreaks.com/topic/117237-registering-on-my-website-mysql-syntax-error/#findComment-603200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.