Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/64294-insert-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/64294-insert-help/#findComment-320553
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.