I’m really NEW at php and trying to learn the best I can. I’ve figured out on my own(and the net of course) to build a form using POST to save data to a SQL database. I cannot for the life of me find anything to help me validate the data. I’m sorry if this is sloppy code or a really STUPID QUESTION to the experts online answering forum posts on other sites (which is the vibe I get from them).
I’m hoping it’s easier to learn here. Any help or a point in the right direction would be awesome. I’m just stuck is all. Thanks.
Form:
Student Application Form
Which campus are you applying to?
Birth Date:
Contact Information:
Firstname:
Lastname:
E-mail:
Phone:
Cell:
Address:
etc. etc. Scripting:
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ’ . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected) {
die('Can’t use ’ . DB_NAME . ‘:’ . mysql_error());
}
$campus = $_POST[‘campus’];
$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$transportation = $_POST[‘transportation’];/checkbox variable/
$transporttype = $_POST[‘transporttype’];
$messagebox = $_POST[‘messagebox’];
$email = $_POST[‘email’];
$dob = $_POST[‘dob’];
$uscitizen = $_POST[‘uscitizen’];
$veteran = $_POST[‘veteran’];
$transfer = $_POST[‘transfer’];
$working = $_POST[‘working’];
$ftpt = $_POST[‘ftpt’];
$employer = $_POST[‘employer’];
$sql = “INSERT INTO application (firstname, lastname, transportation, transporttype, messagebox,
campus, email, dob, uscitizen, veteran, transfer, working, ftpt, employer) VALUES
(’$firstname’,’$lastname’,’$transportation’,’$transporttype’,’$messagebox’,’$campus’,
‘$email’,’$dob’,’$uscitizen’,’$veteran’,’$transfer’,’$working’,’$ftpt’,’$employer’)”;
if (!mysql_query($sql)) {
die('Error: ’ . mysql_error());
}
mysql_close();
?>