1
I’m trying to record some checkbox
plus the ID
product in my database MySQL
but I’m not getting it, what I have so far is this:
The form:
<input class="chk" type="checkbox" name="cores[]" value="<?php echo $row_RsCores['id_cor_textura']; ?>" />
<input name="IdProduto" type="hidden" value="<?php echo $id_produto; ?>">
The script that should perform the recording:
// RESGATE DAS VARIÁVEIS
$IdProduto = $_POST['IdProduto'];
$itens = $_REQUEST['cores'];
if (!empty($itens)) {
$qtd = count($itens);
for ($i = 0; $i < $qtd; $i++) {
// echo $itens[$i];//imprime o item corrente
mysql_select_db($database_conexao, $conexao);
$query = "INSERT INTO produto_textura
(id_produto,
id_cor_textura
)
VALUES
('$IdProduto',
'$itens[$i]')";
}
$queryExec = mysql_query($query, $conexao) or die( "Erro ao inserir checks no banco de dados.");
}
The error that occurs is this:
"Erro ao inserir checks no banco de dados."
Man MySQL
is like this:
ve what error is wrong? $queryExec = mysql_query($query, $connected) or die('Invalid query: ' . mysql_error());
– Marcelo Diniz
Hello @Marcelodiniz, I just appeared "1" and is being sent to the bank only the last record.
– adventistapr
Is it always the same product id(that Hidden input)? and
mysql_select_db
must be out of for. Another test you can do is to print the generated sqls and run them all in the database at once.– rray
Hello $rray, yes the product will be inserted only once and I gave an echo to show the generated sql and it just shows me the last record of 4 I’m trying to iserir.
– adventistapr