I've put together a script to process the form data, but it doesn't seem to be working. Unfortunately, I'm not exprienced enough wth PHP to figure this out... it's probably obvious...
Anyway, here's the code I'm using:
Code: Select all
<?php require "db_connect.php"; //this gets the username, host, dbname, password variables to connect to the database
//we check to make sure this page was accessed by someone hitting the submit button
if(isset($_POST['Submit'])) {
//then we make sure that all questions were answered Yes - if not then redirect to not qualified page
if $_POST['age'] != "Yes" {
header('Location: not-qualified.html');
}
if $_POST['before13'] != "Yes" {
header('Location: not-qualified.html');
}
if $_POST['waking'] != "Yes" {
header('Location: not-qualified.html');
}
if $_POST['substancefree'] != "Yes" {
header('Location: not-qualified.html');
}
if $_POST['humanlike'] != "Yes" {
header('Location: not-qualified.html');
}
//made it through all validation without being redirected, so need to reset variables to take account of globals being off
$age = $_POST['age'];
$before13 = $_POST['before13'];
$waking = $_POST['waking'];
$substancefree = $_POST['substancefree'];
$humanlike = $_POST['humanlike'];
$date = date('Y-m-d H:i:s');
//This is where we connect to the database
$db = mysql_pconnect($db_host, $db_user, $db_pass);
if (!$db) {
//this gives a warning if we can't connect to the database, and then exits
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
//this is the statement that connects to the database table and inserts the new values
//first we do the selecting of the database
//then we define the command with $sql -- telling it to INSERT data into the table fields listed
//and then telling it what data to put in those fields by calling on the POSTed variables from the form
mysql_select_db($db_name, $db);
$sql_qualify = ("INSERT INTO qualify (
age,
before13,
waking,
substancefree,
humanlike,
date)
VALUES (
'$age',
'$before13',
'$waking',
'$substancefree',
'$humanlike',
'$date');");
$result_qualify=mysql_query($sql_qualify,$db) or die("<P>Query failed: ".mysql_error()); //then we tell it to perform the instructions, or give an error message
//Database query is then be followed by another redirect to the second part of the prequalification questionnaire
header(location: initial-q2.html);
//if this page was reached without hitting the submit button on the form, give an error message
} else {
echo "You did not submit the associated form... you should not be here.";
}
?>Thanks,
Scott
edit patrikG: replaced
Code: Select all
withCode: Select all
-tags for readibility