mercredi 31 décembre 2014

Checkbox value comes with single value

My code is working but there are problem if i choised both of value from form and then only single value added database. Where is going wrong.



<?php
$con = mysqli_connect('localhost', 'root', '12345', 'fruit');
if ($_SERVER['REQUEST_METHOD'] != 'POST' && !isset($_POST['submit'])) {
echo '<form action="" method="post">
<input type="checkbox" name="fruits[]" value="Apple" />APPLE<br />
<input type="checkbox" name="fruits[]" value = "Lemon" />LEMON<br />
<input type="submit" name="submit" value="POST">
</form>';
}elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])){
$fruit = $_POST['fruits'];
foreach ($fruit as $fruits){
$fruits = mysqli_real_escape_string($con, strip_tags($fruits));
}
$sql_add = mysqli_query($con, "INSERT INTO fruit (name) VALUES ('$fruits')");
if (mysqli_affected_rows($con) == 1) {
echo "Ok not problem.";
}else {
echo "There are some problem. Please submit your choice again.";
}
}




Aucun commentaire:

Enregistrer un commentaire