Freid001 Posted July 23, 2010 Share Posted July 23, 2010 Hi every one I am trying to make my own php and MySQL data base game! However i have got stuck on the registration below is the error i get when i try to enter a record i to MySQL data base: 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 'Name) VALUES ('', 'freid', 'freid001@hotmail.co.uk, 'freid', 'clan')' at line 1 I am unsure as to what this means ? I have posted the php registration code i am using below: "><?php function showheader ($title) { } function showfooter () { } $host= "mysql"; $mysql_user = "XXXXXXX"; $mysql_password = "XXXXXXX"; $mysql_database = "XXXXXXX"; $Name = $_POST['myusername']; $Password = strtolower(strip_tags ($_POST['Password1'])); $Password2 = strtolower(strip_tags ($_POST['Password2'])); $myusername = strtolower(strip_tags ($_POST['myusername'])); $clan = $_POST['Clan']; $email = $_POST['email']; $myusername = $_POST['myusername']; $check = $_POST['check']; $check2 = "4720"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $db = mysql_select_db($mysql_user,$mysql_password); if ($Password == $Password2) { if ($check == $check2) { if (strlen($Password)>25||strlen($Password)<6) { echo "Password must be between 6 and 25 characters! "; } if (strlen($myusername)>25||strlen($myusername)<3) { echo "Username must be between 3 and 25 characters! "; } $user = mysql_query("SELECT * FROM Game WHERE user ='$myusername'"); if (mysql_num_rows($user) > 0) { echo "We are sorry to inform you that the User Name echo $Name Has already Be Taken!"; showfooter(); } else { $query = "INSERT INTO user (ID, User, Email, Password, Fac Name) VALUES ('', '$myusername', '$email, '$password', 'clan')"; mysql_query($query) or die (mysql_error()); include 'library/closedb.php'; echo "New MySQL user added"; } } else { showheader("Registration Error!"); echo "Please enter the conformation code correctly!"; showfooter(); } } else { showheader("Registration Error!"); echo "Your Two Passwords Did Not Match!"; showfooter(); } ?> I think that this part of the code is wrong but im not sure $query = "INSERT INTO user (ID, User, Email, Password, Fac Name) VALUES ('', '$myusername', '$email, '$password', 'clan')"; mysql_query($query) or die (mysql_error()); Any help with the matter will be much appericiated. to view the code on the web site please go to http://www.europeanwar.ulmb.com thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 Fac Name ^^^ If you in fact have a column with a two word name, it requires special handling. You must enclose it in back-ticks `` every time you put it into a query. You could also rename it to use an under-score Fac_Name instead of a space so that it would become a one-word column name. Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090184 Share on other sites More sharing options...
Freid001 Posted July 23, 2010 Author Share Posted July 23, 2010 I have made the adjustments you have send and i still get the error 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 ''ID', 'User', 'Email', 'Password', 'Clan') VALUES ('', 'freid', 'freid, 'fireid001@hotmail.co.uk', 'freid'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090260 Share on other sites More sharing options...
Maq Posted July 23, 2010 Share Posted July 23, 2010 Can you post just the current $query line? Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090261 Share on other sites More sharing options...
awjudd Posted July 23, 2010 Share Posted July 23, 2010 It appears that your field names in your list are in single quotes. This is invalid because they will be treated as individual strings. If you want to delimit the field values use the `. i.e. INSERT INTO `blah` ( `id`, `blah2` ) VALUES ( NULL, 'Hi' ) That should resolve your issue. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090281 Share on other sites More sharing options...
PFMaBiSmAd Posted July 23, 2010 Share Posted July 23, 2010 Freid001, not only did you change the column name that was causing the first error, you put single-quotes around each of your column names. Why did you do that and if you bother to look at the error message you got, it is complaining at the first single-quote that you put around your ID column name. Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090307 Share on other sites More sharing options...
Freid001 Posted July 23, 2010 Author Share Posted July 23, 2010 oh sorry i though you ment '' any way I see to be a step closer i now get a error message that says: Unknown column '' in 'field list' I have changing the name to faction but it still gives this error $query = "INSERT INTO Game (`ID`, `User`, `Email`, `Password`, `Faction`) VALUES (``, `$myusername`, `$email`, `$password`, `$clan`)"; mysql_query($query) or die (mysql_error()); include 'library/closedb.php'; echo "New MySQL user added"; Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090366 Share on other sites More sharing options...
Freid001 Posted July 23, 2010 Author Share Posted July 23, 2010 Thanks guys I have got it working! Im only 17 and so the more advance php is a little unknown to me so thanks for your help :) You can check it out at http://www.europeanwar.ulmb.com if you like! Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090370 Share on other sites More sharing options...
Maq Posted July 23, 2010 Share Posted July 23, 2010 Thanks guys I have got it working! Im only 17 and so the more advance php is a little unknown to me so thanks for your help :) Glad you got it working but your code changed every time you posted it and it's hard for people to help when that happens. You should also mark this thread as solved. Quote Link to comment https://forums.phpfreaks.com/topic/208663-mysql-syntax-error-please-help/#findComment-1090389 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.