davelearning Posted January 5, 2011 Share Posted January 5, 2011 Hi all, I am relatively new to php and am stuck on a simple query, I just dont know what my error is. Basically I am just trying to save some information to a database and I am getting: 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 'key) VALUES ('testuser','dc23053d9ada11806420839fd42aa9c9','admin@jollyhosting' at line 1Something Went Wrong = Please click back and try again The code I am using is <?php include('config.php'); require('class.phpmailer.php'); $username = $_POST['username']; $hide = md5($_POST['password']); $password = $hide; $email = $_POST['email']; $number = rand(); $key = md5($number); $query ="INSERT INTO user (username, password, email, key) VALUES ('$username','$password','$email', '$key')"; if (!mysql_query($query)) { echo mysql_error(); echo "Something Went Wrong = Please click back and try again"; } Many thanks for anyhelp Quote Link to comment Share on other sites More sharing options...
Maq Posted January 5, 2011 Share Posted January 5, 2011 Your column 'key' is a reserved MySQL word. You can place backticks `key` around the column name everywhere it's referenced. You should try to avoid naming your columns after reserved words. Quote Link to comment Share on other sites More sharing options...
davelearning Posted January 5, 2011 Author Share Posted January 5, 2011 Ah, many thanks Maq I guess my username is very apt Also sorry for posting in the wrong section, I wasn't sure if my problem was with my php or my query. 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.