I'm doing a page in html with the checkboxes to insert into string form inside a table row, but if I do not mark all the options it gives an error (but inserts into the bank), how do I get rid of this error if in case I choose only one value from the checkbox?
Notice: Undefined index: plastic in C: \ xampp \ htdocs \ TCC \ postage.php on line 4
Notice: Undefined index: papelao in C: \ xampp \ htdocs \ TCC \ postage.php on line 5
include_once("setting.php");
$plastico = $_POST ['plastico'];
$papelao = $_POST ['papelao'];
$metal = $_POST['metal'];
$madeira = $_POST['madeira'];
$vidro = $_POST['vidro'];
$array = array ($plastico, $papelao, $metal, $madeira, $vidro);
foreach ($array as $key => $valor) {
$campo[]= $valor;
//echo $campo."<br/>";
}
$teste = implode(',',$campo);
try{
$sql = "INSERT INTO postagens (descricao) VALUES ('$teste')";
echo $sql;
$res = mysqli_query($conn, $sql);
$linhas = mysqli_affected_rows($conn);
if ($linhas ==1){
echo "registro gravado com sucesso";
}else{
echo "falha na gravaçao";
}