I'm trying to insert information into multiple checkbox information at once, for example a news item is related to more than one category, so I just select the categories and save, but this is giving this error,
Notice: Array to string conversion in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 19
ErroArray ( [0] => HY000 [1] => 1366 [2] => Incorrect integer value: 'Array' for column 'carteira_id' at row 1 )
Notice: Undefined variable: idlogado in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 32
Notice: Array to string conversion in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 19
ErroArray ( [0] => HY000 [1] => 1366 [2] => Incorrect integer value: 'Array' for column 'carteira_id' at row 1 )
Notice: Undefined variable: idlogado in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 32
Notice: Array to string conversion in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 19
ErroArray ( [0] => HY000 [1] => 1366 [2] => Incorrect integer value: 'Array' for column 'carteira_id' at row 1 )
Notice: Undefined variable: idlogado in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 32
Notice: Array to string conversion in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 19
ErroArray ( [0] => HY000 [1] => 1366 [2] => Incorrect integer value: 'Array' for column 'carteira_id' at row 1 )
Notice: Undefined variable: idlogado in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 32
Notice: Array to string conversion in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 19
ErroArray ( [0] => HY000 [1] => 1366 [2] => Incorrect integer value: 'Array' for column 'carteira_id' at row 1 )
Notice: Undefined variable: idlogado in C:\Program Files\VertrigoServ\www\painel\pg\cadamsg.php on line 32
There were several errors because there are all checked checkboxes there is the code
<?php
foreach ($carteira as $cart) {
echo '
<div class="checkbox i-checks">
<label>
<input type="checkbox" name="f_carteira[]" value="'.$cart['id'].'">
<i></i>
'.$cart["nome"].'
</label>
</div> ' ;
}
?>
insert
<?php
session_start();
include '../config/config.inc.php';
error_reporting(E_ALL);
if (isset($_POST["submit"])) {
$carteira = $_POST['f_carteira'];
if($carteira){
foreach ($carteira as $car) {
$cadastrarmensagem = $pdo->prepare("INSERT INTO mensagem(codigo,conteudomsg,categoria_id,carteira_id,usuario_id) VALUES(:codigo,:conteudo,:categoria,:carteira,:usuarioid)");
$cadastrarmensagem->bindValue(":codigo",$_POST["f_codigo"]);
$cadastrarmensagem->bindValue(":conteudo",$_POST["f_msg"]);
$cadastrarmensagem->bindValue(":categoria",$_POST["f_cat"]);
$cadastrarmensagem->bindValue(":carteira",$_POST["f_carteira"]);
$cadastrarmensagem->bindValue(":usuarioid",$_POST["f_usuario"]);
$cadastrarmensagem->execute();
$linha = $cadastrarmensagem->rowCount();
if($linha > 0){
echo "Mensagem Cadastrada com Sucesso";
header ("Location: ../index.php?pg=mensagens");
}else {
echo "Erro";
//imprimindo erro da variavel de consulta
print_r($cadastrarmensagem->errorInfo());
echo "$idlogado";
}
}
}
}else{echo "aconteceu algum erro";}
?>