i have an html page, where there is a form and saves the results into MySQL. The problem is that the checkbox, saves only one value on the MySQL table. What do i have to do, in order to save multiple values inside the db column?
HTML CODE:
<fieldset>
<input type = "checkbox" name = "rating[]" value = "Homepage">Homepage
<input type = "checkbox" name = "rating[]" value = "Facilities"> Facilities
<input type = "checkbox" name = "rating[]" value = "Reservation"> Reservation
<input type = "checkbox" name = "rating[]" value = "Contact"> Contact
<input type = "checkbox" name = "rating[]" value = "current"> The current one
</fieldset>
PHP CODE:
$con=mysqli_connect("xxx","zzz","yyy","xxx");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$postcode = mysqli_real_escape_string($con, $_POST['postcode']);
$country = mysqli_real_escape_string($con, $_POST['country']);
$phonenumber = mysqli_real_escape_string($con, $_POST['phonenumber']);
$rating = mysqli_real_escape_string($con, $_POST['rating_value']);
$subscribe = mysqli_real_escape_string($con, $_POST['subscribe']);
for($i=0; $i<count($rating); $i++) { $rating_value &= $rating[$i];}
$sql="INSERT INTO customers (firstname, lastname, password, email, address, postcode, country, phonenumber, rating, subscribe)
VALUES ('$firstname', '$lastname', '$password', '$email', '$address', '$postcode','$country', '$phonenumber', '$rating_value', '$subscribe')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo " Success!";