Đang cập nhật

How to insert multiple checkbox values into one mysql table (field) using php
How to insert multiple checkbox values into one mysql table (field) using php
Hi Guys,
Looking for some desperately.
I am new to php, with a lot search I have been able to put together some form of working script. The problem I am now facing is I have multiple checkboxes for the users to select from but the selected checkbox value does not get inserted into the table instead shows as “Array”. With some help I plan to get all the selected checkbox values into one table.
I have two files one "testpage.html" which contains the form and the other "test_post.php" to process the form data. Please find below html and php file codes. Have to // in front of every code in html so the code can be seen.
Really appreciate your help in advance.
HTML form:PHP Code:
PHP code:
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="dbname"; // Database name
$tbl_name="tblname"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$FullName=$_POST['FullName'];
$MobileNumber=$_POST['Number'];
$EmailAddress=$_POST['EmailAddress'];
$Address=$_POST['Address'];
$petathome=$_POST['petathome'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(FullName,Number, EmailAddress, Address, petathome)VALUES('$FullName', '$Number', '$EmailAddress', '$Address', '$petathome')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "
";
echo "Back to main page";
}
else {
echo "ERROR";
}
?>
// close connection
mysql_close();
?>