mickey Posted April 3, 2010 Share Posted April 3, 2010 hi,im totally new in php and mysql.so i try make some fake system just to test. i manage to insert data into 1 table from single form.but when i want to insert certain data into 2nd table using same form,it said i have systax error. but the line for 1st table and 2nd table exactly same except for the variable. is there different syntax to add data into more than 1 table using php and mysql?$sql=("INSERT INTO account (AccName, Char1, Char2, Char3, Char4, Char5) VALUES ( '$_POST[AccName]','$_POST[char1]', '$_POST[char2]', '$_POST[char3]','$_POST[char4]','$_POST[char5]')");$sql2=("INSERT INTO character (CharName, Class, Level, AccName, GuildName) VALUES ( '$_POST[char1]','$_POST[class1]', '$_POST[level1]', '$_POST[AccName]','$_POST[Guild1]')");if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }if (!mysql_query($sql2,$con)) { die('Error: ' . mysql_error()); }please help this noob Link to comment Share on other sites More sharing options...
jeffman Posted April 3, 2010 Share Posted April 3, 2010 You should not use different syntax for the 2 queries. That would make so sense at all.Let us be clear about the problem. Are you being warned about a PHP syntax error, or is it a mysql syntax error?A mysql error might be caused by strange or empty values in your $_POST elements. Does your script test them before trying to use them? Link to comment Share on other sites More sharing options...
mickey Posted April 3, 2010 Author Share Posted April 3, 2010 You should not use different syntax for the 2 queries. That would make so sense at all.Let us be clear about the problem. Are you being warned about a PHP syntax error, or is it a mysql syntax error?A mysql error might be caused by strange or empty values in your $_POST elements. Does your script test them before trying to use them?its sql systax error..it ask to check syntax that to be use near 'character (CharName, Class.......i dont understand what u mean i should not use different syntax for the 2 queries?which part is the different?and there no empty elements..but i will double check again all the spelling Link to comment Share on other sites More sharing options...
jeffman Posted April 3, 2010 Share Posted April 3, 2010 This was your question: is there different syntax to add data into more than 1 table using php and mysql?This was my answer:You should not use different syntax . . .That seems pretty clear to me.Anyway, I think the problem is very simple. The word "character" turns out to be a reserved word and may not be used without quotes or backticks. Try:INSERT INTO `character` . . .I apologize for not thinking about that sooner. Link to comment Share on other sites More sharing options...
mickey Posted April 3, 2010 Author Share Posted April 3, 2010 i try put the quote.its not working but u said it a reserved words...so i change the table name..it works..big thanx to you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.