I'm making a php form that writes the values inside a TXT database. In the form there are several multiple checkboxes (Zona) that can be selected in more options. How can I write all the selected values in the database?
My code:
Form:
<html>
<body>
<form enctype="multipart/form-data" action="action.php" method="post">
<label for="guasto">Guasto</label>
<input type="text" id="guasto" name="guasto" />
<input type="checkbox" name="zona" value="zona 1"> zona 1<br>
<input type="checkbox" name="zona" value="Zona 2" > zona 2<br>
<input type="checkbox" name="zona" value="Zona 3" > zona 2<br>
<label for="causa">Causa Guasto</label>
<input type="text" id="causa" name="causa" />
<label for="risoluzione">Tempi di risoluzione</label>
<input type="text" id="risoluzione" name="risoluzione" />
<input type="submit" name="Salva" value="Salva" />
</form>
</form>
</body>
</html>
Action.php
include("setting.php");
/*************************
SAVE
**************************/
if(isset($_POST['Salva']))
{
if(!is_writable($my_database_txt)){
exit("The file does not have write permissions!");
}
//
$bad_char = array("|", "\r\n", "\r", "\n");
$guasto = str_replace($bad_char, "", $_POST['guasto']);
$zona = str_replace($bad_char, "",$_POST['zona']);
$causa = str_replace($bad_char, "", $_POST['causa']);
$risoluzione = str_replace($bad_char, "", $_POST['risoluzione']);
//
$open = fopen($my_database_txt, "a+");
// scriviamo i dati separati dal carattere separatore
fwrite($open, $guasto."|".$zona."|".$causa."|".$risoluzione."\r\n");
//
fclose($open);
//
header("location: vista.php");
exit;
}
How can i save multiple checkbox array?
Aucun commentaire:
Enregistrer un commentaire