bravo81 Posted June 13, 2008 Share Posted June 13, 2008 Hi everyone, I am trying to INSTERT INTO my MySQL DB Table when someone registers. But I do not want to create Values for every field, is that possible? Its not working so far, I am defining the fields I wish to fill in with the Data supplied in the submit form. mysql_query("INSERT INTO `users` (username, password, email, activecode, activated, tut, status) VALUES ($reg_username, $randompassword, $email, $code, 0, 0, Alive)"); if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); The website is: www.southernheavenflorida.com/quarantime.com Thanks for any help/comments. Dean. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 Well, you'ld need to quote "Alive"... but if you don't want the values, don't list the column name (assuming you have suitable defaults in strict mode, or strict mode is disabled). Quote Link to comment Share on other sites More sharing options...
bravo81 Posted June 13, 2008 Author Share Posted June 13, 2008 Thanks Fenway, I will try that. I have not got Defaults in all off the Fields, but I am not listing hte Column name so it should just be ok yeh? Im getting this error: Query failed: 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 '@hotmail.co.uk, ykyc4h67, 0, 0, Alive)' at line 2 The Email field has about 10 other fields between it and "Password". Is that why the error comes up? Thanks, Dean. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 You didn't read my comment about the "alive" value before... quote it! In fact, quote all of your values! mysql_query("INSERT INTO `users` (username, password, email, activecode, activated, tut, status) VALUES ('$reg_username', '$randompassword', '$email', '$code', 0, 0, 'Alive')"); if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); Quote Link to comment Share on other sites More sharing options...
bravo81 Posted June 13, 2008 Author Share Posted June 13, 2008 I have done that, Now my code is: mysql_query("INSERT INTO `users` ('username', 'password', 'activated', 'online', 'email', 'status', 'tut', 'activecode') VALUES ('$reg_username', '$randompassword', '0', '0', '$email', 'Alive', '0', '$code')"); if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); I have removed all other columns that I am not using. Also, the code is inserting into the columns in order. The error I get now is: Query failed: 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 ''username', 'password', 'activated', 'online', 'email', 'status', 'tut', 'active' at line 1 Any ideas? Thanks, Dean. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 Only place quotes around values, not field/table names. mysql_query("INSERT INTO `users` (username, `password`, activated, online, email, status, tut, activecode) VALUES ('$reg_username', '$randompassword', '0', '0', '$email', 'Alive', '0', '$code')"); if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 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.