View Single Post
Old 08-07-2012, 04:03 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Try this:

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'];

// Loop through the array of checked box values ...
$pets="";
$flag=0;
foreach(
$petathome as $entry){
$pets .= $entry."|";
$flag=1;
}
if(
$flag==1){
$pets=rtrim($pets);
}

// Insert data into mysql
$sql="INSERT INTO $tbl_name(FullName, Number, EmailAddress, Address, petathome)VALUES('$FullName', '$Number', '$EmailAddress', '$Address', '$pets')"
$result=mysql_query($sql);

// 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();
?>



.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
mohammedsali (08-07-2012)