Ok, no problem....here's all the code...........there is a LOT of things I have commented out that I tried b4 and wasn't sure if I should just wipe out yet or not.
Code: Select all
<?php
$con = new PDO("mysql:host=myhost_isreallymyhost;dbname=ilmcompetition", myUserNameIsReallyMyUserName, myPasswordIsReallyMyPassword)
or
die("Couldn't connect to specificied datasource.");
// Create a tokenized query string to pass to our statement object.
/**
* Array, instead of a switch:
*/
$query = "
INSERT INTO {$table_to_insert_to[$levels]} (
name, address, city, state, zip, phone,
dob, parent, email, pName, pAddress, pCity, pState, pZip,
pPhone, pDob, pParent, pEmail
) VALUES (
:name, :address, :city, :state, :zipcode, :phone,
:dob, :parent, :email, :name2, :address2, :city2, :state2, :zipcode2,
:phone2, :dob2, :parent2, :email2
)
";
$my_statement = $con->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zipcode" => $zip1, // You had it referencing "zip", a non-token
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zipcode2" => $zip2, // again, referencing "zip2" instead of "zipcode"
"phone2" => $ph2,
"dob2" => $dob2,
"parent2" => $parentName2,
"email2" => $email2));
if( !$my_result )
{
print_r($con->errorInfo());
}
[b]/*[/b]switch($levels)
{
case "preE":
$preE_status='checked';
$query = "
INSERT INTO pre_elementary (
) VALUES (
)
";
// prepare the statement for execution. When we execute the statement, we pass
// an array containing the parameters we wish to use for our query (in the query,
// these parameters are represented by tokens prefixed with ':')
//
// PDO will handle the data sanitizing for us with these two steps.
$my_statement = $p->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zip" => $zip1,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zip2" => $zip2,
"phone2" => $ph2,
"parent2" => $parentName2,
"email2" => $email2));
if( !$my_result )
{
print_r($p->errorInfo());
}
break;
case "elem":
$elem_status='checked';
$query = "
INSERT INTO elementary (
id, name, address, city, state, zip, phone, dob, parent, email,
pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail
) VALUES (
NULL, :name, :address, :city, :state, :zipcode, :phone, :dob, :parent, :email,
:name2, :address2, :city2, :state2, :zipcode2, :phone2, :parent2, :email2
)
";
$my_statement = $p->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zip" => $zip1,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zip2" => $zip2,
"phone2" => $ph2,
"parent2" => $parentName2,
"email2" => $email2));
break;
case "inter":
$inter_status='checked';
$query = "
INSERT INTO intermediate (
id, name, address, city, state, zip, phone, dob, parent, email,
pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail
) VALUES (
NULL, :name, :address, :city, :state, :zipcode, :phone, :dob, :parent, :email,
:name2, :address2, :city2, :state2, :zipcode2, :phone2, :parent2, :email2
)
";
$my_statement = $p->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zip" => $zip1,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zip2" => $zip2,
"phone2" => $ph2,
"parent2" => $parentName2,
"email2" => $email2));
break;
case "junior":
$junior_status='checked';
$query = "
INSERT INTO junior (
id, name, address, city, state, zip, phone, dob, parent, email,
pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail
) VALUES (
NULL, :name, :address, :city, :state, :zipcode, :phone, :dob, :parent, :email,
:name2, :address2, :city2, :state2, :zipcode2, :phone2, :parent2, :email2
)
";
$my_statement = $p->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zip" => $zip1,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zip2" => $zip2,
"phone2" => $ph2,
"parent2" => $parentName2,
"email2" => $email2));
break;
case "senior":
$senior_status='checked';
$query = "
INSERT INTO junior (
id, name, address, city, state, zip, phone, dob, parent, email,
pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail
) VALUES (
NULL, :name, :address, :city, :state, :zipcode, :phone, :dob, :parent, :email,
:name2, :address2, :city2, :state2, :zipcode2, :phone2, :parent2, :email2
)
";
$my_statement = $p->prepare($query);
$my_result = $my_statement->execute(array(
"name" => $name1,
"address" => $address1,
"city" => $city1,
"state" => $state1,
"zip" => $zip1,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zip2" => $zip2,
"phone2" => $ph2,
"parent2" => $parentName2,
"email2" => $email2));
break;
*/
//create short variable names
$name1=$_POST[name1]; $ph1=$_POST[ph1]; $dob1=$_POST[dob1];
$parentName1=$_POST[parentName1]; $email1=$_POST[email1]; $address1=$_POST[address1];
$city1=$_POST[city1]; $state1=$_POST[state1]; $zip1=$_POST[zip1];
$name2=$_POST[name2]; $ph2=$_POST[ph2]; $dob2=$_POST[dob2];
$parentName2=$_POST[parentName2]; $email2=$_POST[email2]; $address2=$_POST[address2];
$city2=$_POST[city2]; $state2=$_POST[state2]; $zip2=$_POST[zip2];
$levels=$_POST[levels]; $submit=$_POST[submit];
$preE_status=$_POST[preE]; $elem_status=$_POST[elem]; $inter_status=$_POST[inter];
$junior_status=$_POST[junior]; $senior_status=$_POST[senior];
/*add slashes before special charachters when input to database
if (!get_magic_quotes_gpc()) {
$name1 = addslashes($name1); $ph1 = addslashes($ph1); $dob1 = addslashes($dob1);
$parentName1 = addslashes($parentName1); $email1 = addslashes($email1); $address1 = addslashes($address1);
$city1 = addslashes($city1); $state1 = addslashes($state1); $zip1 = addslashes($zip1);
$name2 = addslashes($name2); $ph2 = addslashes($ph2); $dob2 = addslashes($dob2);
$parentName2 = addslashes($parentName2); $email2 = addslashes($email2); $address2 = addslashes($address2);
$city2 = addslashes($city2); $state2 = addslashes($state2); $zip2 = addslashes($zip2);
}
$query="INSERT INTO pre_elementary (id, name, address, city, state, zip, phone, dob, parent, email, pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail)
VALUES (NULL, '".$name1."','".$ph1."','".$dob1."','".$parentName1."','".$email1."','".$address1."','".$city1."','".$state1."','".$zip1."','".$name2."','".$ph2."','".$dob2."','".$parentName2."','".$email2."','".$address2."','".$city2."','".state2."','".$zip2."'".$pPhone."','".$pParent."','".pEmail."')";
$sql = "SELECT * FROM pre_elementary";
mysql_query($sql,$con);
$query="INSERT INTO elementary (name, address, city, state, zip, phone, dob, parent, email, pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail)
VALUES (('".$name1."','".$ph1."','".$dob1."','".$parentName1."','".$email1."','".$address1."','".$city1."','".$state1."','".$zip1."','".$name2."','".$ph2."','".$dob2."','".$parentName2."','".$email2."','".$address2."','".$city2."','".state2."','".$zip2."'".$pPhone."','".$pParent."','".pEmail."')";
$query="INSERT INTO intermediate (name, address, city, state, zip, phone, dob, parent, email, pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail)
VALUES ('".$name1."','".$ph1."','".$dob1."','".$parentName1."','".$email1."','".$address1."','".$city1."','".$state1."','".$zip1."','".$name2."','".$ph2."','".$dob2."','".$parentName2."','".$email2."','".$address2."','".$city2."','".state2."','".$zip2."'".$pPhone."','".$pParent."','".pEmail."')";
break;
$query="INSERT INTO junior (name, address, city, state, zip, phone, dob, parent, email, pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail)
VALUES ('".$name1."','".$ph1."','".$dob1."','".$parentName1."','".$email1."','".$address1."','".$city1."','".$state1."','".$zip1."','".$name2."','".$ph2."','".$dob2."','".$parentName2."','".$email2."','".$address2."','".$city2."','".state2."','".$zip2."'".$pPhone."','".$pParent."','".pEmail."')";
break;
$query="INSERT INTO senior (name, address, city, state, zip, phone, dob, parent, email, pName, pAddress, pCity, pState, pZip, pPhone, pParent, pEmail)
VALUES ('".$name1."','".$ph1."','".$dob1."','".$parentName1."','".$email1."','".$address1."','".$city1."','".$state1."','".$zip1."','".$name2."','".$ph2."','".$dob2."','".$parentName2."','".$email2."','".$address2."','".$city2."','".state2."','".$zip2."'".$pPhone."','".$pParent."','".pEmail."')";
break;
default:
echo "You did not select a level please go back and select a level.";
}
[b]*/[/b]
//field validation - if field is null user is asked to complete otherwise confirm and show entries
if (!$name1 || !$ph1 || !$dob1 || !$parentName1 || !$email1 || !$address1 || !$city1 || !$state1 || !$zip1) {
echo "You have not entered all the required information. Please go back and fully complete the form.";
} elseif (!$levels) {
echo "You did not specify which level of competition you are entering. Please go back and specify a level.";
} else {
echo "<h2>Jazak Allah Khair for registering, you will receive an email shortly with your registration number in sha Allah.</h2>";
echo "<p><strong>Your registration information is also below.</strong></p>";
echo "<table cellpadding='3'>";
echo "<tr><td>Name: ".$name1."</td><td>Phone: ".$ph1."</td><td>DOB: ".$dob1."</td><td></td></tr>";
echo "<tr><td>Parent: ".$parentName1."</td><td>Parent Email: ".$email1."</td><td></td><td></td></tr>";
echo "<tr><td>Address: ".$address1."</td><td>".$city1."</td><td>".$state1."</td><td>".$zip1."</td></tr></table>";
}
if ($name2 || $ph2 || $dob2 || $parentName2 || $email2 || $address2 || $city2 || $state2 || $zip2) {
echo "<table cellpadding='3'><tr><td>Partners Name: ".$name2."</td><td>Partners Phone: ".$ph2."</td><td>Partners DOB: ".$dob2."</td><td></td></tr>";
echo "<tr><td>Partners Parent: ".$parentName2."</td><td>Partners Email: ".$email2."</td><td></td><td></td></tr>";
echo "<tr><td>Partners Address: ".$address2."</td><td>".$city2."</td><td>".$state2."</td><td>".$zip2."</td></tr>";
} else {
echo "<tr><td colspan='4'>You have choosed to enter without a partner - if you change your mind, please contact us via email.</td></tr></table>";
}
?>