I have a similar issue to insert multiple rows via a php array into mysql but I want to insert array both into the columns and values in my database.
The columns are from a json_decode string and is working properly when I am inserting static values like below
$columns = implode(",",$key_string);
$results = array(NULL, 'test');
$results_in = implode(",",$results);
$sql_store = "INSERT into dabas_test (".$columns.") VALUES (NULL, 'test')";
$sql = mysqli_query($db, $sql_store) or die(mysql_error());
I want to insert around 150 values into 150 columns but want to try the code with 2 values. But when I am using the code below
$columns = implode(",",$key_string);
$results = array(NULL, 'test');
$results_in = implode(",",$results);
$sql_store = "INSERT into dabas_test (".$columns.") VALUES (".$results_in.")";
$sql = mysqli_query($db, $sql_store) or die(mysql_error());
I then get the following error message:
Error description: 1054 Unknown column 'test' in 'field list'
As if test
would be the column, cannot figure this out!
Thanks for help