Jump to content

Inserting Array Values into table columns.


phileplanet

Recommended Posts

I basically want each value in the array to go into its own column. here's what I have so far:

[code]$columns = array();
$values = array();
foreach($formfields as $field) {
    $column = $field[2];
    $value = $_POST["$column"];
    array_push($columns, $column);
    array_push($values, $value);
}
$q = mysql_query("INSERT INTO $table($columns) VALUES($values)") or die (mysql_error());?>[/code]
When I try to INSERT, it gives me "Unknown column 'Array' in 'field list'". Any solutions?
Link to comment
https://forums.phpfreaks.com/topic/5817-inserting-array-values-into-table-columns/
Share on other sites

Yes, good. Well done. I recommend that you use one of these on each value before being inserted/updated in the table:

mysql_real_escape_string(), mysql_real_escape_string(), or addslashes()

[a href=\"http://us2.php.net/manual/en/function.mysql-escape-string.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.mysq...cape-string.php[/a]

[a href=\"http://us2.php.net/manual/en/function.addslashes.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.addslashes.php[/a]

But first make sure you know what you're magic_quotes setting is before applying the above type of functions on form data. See:

[a href=\"http://us2.php.net/manual/en/function.get-magic-quotes-gpc.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.get-...-quotes-gpc.php[/a]

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.