l3asturd Posted August 10, 2007 Share Posted August 10, 2007 OK, I have a working insert script, but I was trying to create a new one when I ran in to a problem When using: <?php $insert = mysql_query("INSERT INTO $dbtable (Name,Location,Age) VALUES ('test','test','test')"); ?> the result seems to work fine, however, when I add fields and values I seem to hit a syntax boundary. <?php $insert = mysql_query("INSERT INTO $dbtable (Name,Location,Age,Sex,Games,Nick,Tables,Hands,Feet) VALUES ('test','test','test','test','test','test','test','test','test')"); ?> The last code results in no entries. When I checked my SQL portal it says syntax error. I'm guessing there's some kind of query length limit, am I right? I've tried inserting the data using a $field_names array and a $values array, but still get the same result. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/ Share on other sites More sharing options...
MadTechie Posted August 10, 2007 Share Posted August 10, 2007 i am guessing that some of the data has a single quote try using addslashes ie $Name = addslashes($Name); Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320530 Share on other sites More sharing options...
lemmin Posted August 10, 2007 Share Posted August 10, 2007 The string "Tables" is reserved.. I think. Try changing the "Tables" field to something else and see if you still get the error. Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320533 Share on other sites More sharing options...
MadTechie Posted August 10, 2007 Share Posted August 10, 2007 or use `Tables` but yes its better to change it (didn't even see that) time for a break i guess! Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320535 Share on other sites More sharing options...
l3asturd Posted August 10, 2007 Author Share Posted August 10, 2007 Acutally those field names are just for show, the actual field names are like WANMAC,LANMAC,Service etc. Disregard the field names. Also, the data as of yet is just 'test'. I don't have a table full of data yet, I'm trying to create one. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320542 Share on other sites More sharing options...
l3asturd Posted August 10, 2007 Author Share Posted August 10, 2007 Here's the line of code I used for inserting the arrays into the table: <?php $insert_result = mysql_query("INSERT INTO $dbTable (".join(',',$field_names).") VALUES(".join(',',$values).")", $conn); ?> However when I have more than 5 fields with values the SQL goes kaput as if there is a limit for each query syntax length. I know it's got to be something in my code because people obviously have more than 5 fields in there tables. Quote Link to comment https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320553 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.