PHP Required Fields
Posted: Fri Oct 10, 2008 9:04 pm
I know this is "easy", and I've been allover the internet trying to make this work but can't, so I am hoping someone with more PHP knowledge than I can help me with this. I just want all my fields required, but how? The code is below:
The form itself:
And this is the insert.php file:
Please, any help would be appreciated greatly!
The form itself:
Code: Select all
<form action="insert.php" method="post">
<div id="header"><h1>IRW Fall 2008 Questionaire</h1></div>
<div id="content">
<br /><div id="questions">Your Name:</div> <input type="text" name="name" />
<br /><br />
<div id="questions">Your email: </div><input type="text" name="email" />
<br /><br />
<div id="questions">Age:</div><br />
<input type="radio" name="age" value="18 - 21"> 18 - 21
<br>
<input type="radio" name="age" value="21 - 26"> 21 - 36
<br>
<input type="radio" name="age" value="37 - 54"> 37 - 54
<br>
<input type="radio" name="age" value="55 - 64"> 55 - 64
<br>
<input type="radio" name="age" value="65 or above"> 65 and above
<br /><br />
<div id="questions">Gender:</div><br />
<input type="radio" name="sex" value="Male"> Male
<br>
<input type="radio" name="sex" value="Female"> Female
<br /><br />
<div id="questions">Household Income:</div><br />
<input type="radio" name="income" value="$40,000 and under"> $40,000 and under
<br>
<input type="radio" name="income" value="$40,001 - $75,000"> $40,001 - $75,000
<br>
<input type="radio" name="income" value="$75,001 - $125,000"> $75,001 - $125,000
<br>
<input type="radio" name="income" value="$125,001 - $200,000"> $125,001 - $200,000
<br>
<input type="radio" name="income" value="$200,001 and above"> $200,001 and above
<br /><br />
<div id="questions">Education Level:</div><br />
<input type="radio" name="edu" value="High School Graduate"> High School Graduate
<br>
<input type="radio" name="edu" value="Some College"> Some College
<br>
<input type="radio" name="edu" value="College Graduate"> College Graduate
<br>
<input type="radio" name="edu" value="Graduate School"> Graduate School
<br /><br />
<div id="questions">Children in Home:</div><br />
<input type="radio" name="children" value="Yes"> Yes
<br>
<input type="radio" name="children" value="No"> No
<br /><br />
<div id="questions">How much have you spent on the last 3 months on apparel, accessories and beauty:</div><br />
<br>
<input type="radio" name="apparel" value="$2,500 and under"> $2,500 and under
<br>
<input type="radio" name="apparel" value="$2,500 - $5,000"> $2,500 - $5,000
<br>
<input type="radio" name="apparel" value="$5,000 - $10,000"> $5,000 - $10,000
<br>
<input type="radio" name="apparel" value="$10,000 - $15,000"> $10,000 - $15,000
<br>
<input type="radio" name="apparel" value="$15,000 - $20,000"> $15,000 - $20,000
<br>
<input type="radio" name="apparel" value="More than $20,000"> More than $20,000
<input name="Date" type="hidden" id="Date" value="<?=date("F j, Y");?>">
<p class="submit"><input type="submit"/></p>Code: Select all
<?php
$con = mysql_connect("host","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Questions (Name, Email, Age, Sex, Income, Edu, Children, Apparel, Date)
VALUES
('$_POST[name]','$_POST[email]','$_POST[age]','$_POST[sex]','$_POST[income]','$_POST[edu]','$_POST[children]','$_POST[apparel]','$_POST[Date]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Thank you for registering for Independent Retail Week: NYC.
You will receive an email shortly with your free 20% coupon.
Enjoy the discounts, fashion and beauty.
- The Nolcha Team";
$subject = 'Free 20% coupon for Independent Retail Week: NYC';
$message = 'Message ';
$header = "From: IRW.com";
mail($_POST['email'],$subject,$message,$header);
mysql_close($con)
?>