Hi Mlseim,
Thank you for taking the time to help me
The html and php code is as below.
HTML form:
PHP Code:
<!DOCTYPE html>
<html>
<body background="blue">
<form action="test_post.php" method="post">
Full Name: <input name="FullName" type="text" id="FullName" /><br />
<br />
Number: <input name="Number" type="text" id="Number" /><br />
<br />
Email Address: <input name="EmailAddress" type="text" id="EmailAddress" /><br /><br />
<br />
Address: <input name="Address" type="text" id="Address" /><br />
<br />
Which animal do you want to keep?<br />
<input type="checkbox" name="petathome[]" value="Dog" />Dog<br />
<input type="checkbox" name="petathome[]" value="Cat" />Cat<br />
<input type="checkbox" name="petathome[]" value="Lion" />Lion<br />
<input type="checkbox" name="petathome[]" value="Tiger" />Tiger<br />
<input type="checkbox" name="petathomel[]" value="Leopard" />Leopard
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP code:
<?php
$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'];
// You have to loop through the array of checked box values ...
$pets="";
foreach($petathome as $entry){
$pets .= $entry.",";
}
// Insert data into mysql
$sql="INSERT INTO $tbl_name(FullName, Number, EmailAddress, Address, petathome)VALUES('$FullName', '$Number', '$EmailAddress', '$Address', '$pets')";
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='testpage.html'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
Please let me know if you want me to start all over again. With fresh table and form, php file. If so please let me know what is to be done.
Thank you once again
Regards,
mohammedsali