View Single Post
Old 08-07-2012, 06:35 PM   PM User | #8
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
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
You'll need a text box.
You will not need to add another checkbox though.
If they put text in the box, that means they want it added to the list.
If they leave the text box blank, it won't get added.

Try this change first.
I'm hoping that using the same name ("petathome[]") for the textbox
will append it to the array, along with the checkbox values.

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="petathome[]" value="Leopard" />Leopard<br />
Also: <input type="text" name="petathome[]"><br />
<
input type="submit" name="submit" value="Submit" />

</
form>
</
body>
</
html
You are allowing user (form) values to be put into your MySQL table.
That can be a security risk (SQL Injections) ... so escape them first ...

PHP Code:
// Get values from form 
$FullName=mysql_real_escape_string($_POST['FullName']); 
$MobileNumber=mysql_real_escape_string($_POST['Number']); 
$EmailAddress=mysql_real_escape_string($_POST['EmailAddress']); 
$Address=mysql_real_escape_string($_POST['Address']); 
$petathome=mysql_real_escape_string($_POST['petathome']); 

EDIT,
I noticed a type on your Leopard checkbox line.
I fixed it in my form (example above).
It might still be bad in your form.

<input type="checkbox" name="petathomel[]" value="Leopard" />Leopard



.

Last edited by mlseim; 08-07-2012 at 06:40 PM..
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
mohammedsali (08-07-2012)