-1
I am making an html page with the checkbox to insert in string form inside a table row, however if I do not mark all options it gives an error (but inserts in the database), how do I make this error disappear if in case I choose only a checkbox value?
Notice: Undefined index: plastico in C: xampp htdocs TCC postagem.php on line 4
Notice: Undefined index: papelao in C: xampp htdocs TCC postagem.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";
}
First of all it is not ERROR but a WARNING, what is occurring is that you are not sending in the POST the fields "plastic" and nor "cardboard".
– Don't Panic
yes, I expressed myself wrong, have to remove the message if I do not choose one of the checkbox options?
– caio
Put on top of your code: error_reporting (0);
– Vuln
Your variable has not been started, if you don’t want to give it importance, review the error_reporting of your hosting, or force your php.ini or . htaccess not to display this, you just need to know which mode runs the interpreter on the server to change the NOTICES, which are not errors. But you better start creating defined variables or treating them before using them to avoid NOTICES.
– ElvisP