ho fatto come mi hai detto
Codice PHP:
$marca=addslashes($_POST['marca']);
$mod=addslashes($_POST['mod']);
$col=addslashes($_POST['col']);
$orig=addslashes($_POST['orig']);
$disp=addslashes($_POST['disp']);
$prezzo=addslashes($_POST['prezzo']);
$prezzoaz=addslashes($_POST['prezzoaz']);
$prezzoriv=addslashes($_POST['prezzoriv']);
$id=addslashes($_POST['id']);
include 'include/conf.inc.php';
function prepareSqlText(&$gpc) {
get_magic_quotes_gpc() && $gpc = stripslashes($gpc);
$gpc = mysql_escape_string($gpc);
}
function prepareSqlVar(&$var) {
if (is_array($var)) {
array_walk($var, 'prepareSqlVar');
} else {
prepareSqlText($var);
}
}
// Prepara TUTTI i post per MySQL
prepareSqlVar($_POST);
// Questi i campi da inserire nella tabella
$fields = array('', 'marca', 'mod', 'col', 'orig', 'disp', 'prezzo', 'prezzoaz', 'prezzoriv','','','id');
// Questi i valori
for ($n = 0; $n < count($_POST['id']); ++ $n) {
foreach ($fields as $field) {
$row[$field] = $_POST[$field][$n];
}
$values[$n] = '(' . implode(',', $row) . ')';
}
// Questa la query
$query = 'INSERT INTO tbl_prodotti (' . implode(',', $fields) . ') VALUES ' . implode(',', $values);
// Questo per vedere come è fatta la query insert con più righe
echo "<pre>$query</pre>";
// Esecuzione della query
mysql_query($query) || die(mysql_error());
ma mi DAQUESTO ERRORE>
INSERT INTO tbl_prodotti (,marca,mod,col,orig,disp,prezzo,prezzoaz,prezzori v,,,id) VALUES (,rterte,366,54,gdgdf,654,5467567,7567567,757657,1 )
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'marca,mod,col,orig,disp,prezzo,prezzoaz,prezzoriv ,,,id) VALUES (