Jump to content

INSERT help


l3asturd

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.