sorry, i forgot to mention that I also want the auto-incremented registrant id and their partner id to be displayed back to the registrant. I would really appreciate a sample code! This site is due to go live tomorrow and I am going to have to already put a notice on the registration page that online registration is not yet available.
All I need is a sample code that will do the following:
1. connect to the database via mySQLi with PHP 5 - (i already have this coded)
2. show errors of connections (already coded)
3. validate the form (already coded)
4. Take these five valuse: radio - preE, radio - elem, radio - inter, radio - junior, radio - senior and..........
if preE is checked write all form values (name, address, ph, dob, email, partner name, partner addy, partner ph, etc.to database table named pre_elementary
then write result of auto incremented id back to user and if values are true for partner also write auto incremented id for partner (table has reg1 as 0 reg2 as 1)
else if elem is checked write all form values to table named elementary and do the above
else if inter is checked do the same
else if junior is checked do the same
else if senior is checked do the same
close db
Below is what I have already that is not writing to the db
$hostname_registration = "my_hosename";
$database_registration = "my_database";
$username_registration = "my_username";
$password_registration = "my_password";
$registration = mysql_pconnect($hostname_registration, $username_registration, $password_registration) or trigger_error(mysql_error(),E_USER_ERROR);
//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];
//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.";
} elseif () {
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>";
}
//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);
}
switch($levels)
{
case "preE": $checkpe = "checked"; break;
case "elem": $checke = "checked"; break;
case "inter": $checki = "checked"; break;
case "junior": $checkj = "checked"; break;
case "senior": $checks = "checked"; break;
}
//This is where I cant figure out what to put for the if statement
$query="insert into pre_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."')";
}
//in my code I have copied the above for all 5 radio if statments but I dont know what to write for the if statement
if ($result = $db->query("SELECT * FROM pre_elementary", MYSQLI_USE_RESULT)) {
if (!$db->query("SET @a:='this will not work'")) {
printf("Error: %s\n", $db->error);
}
$result->close();
}
$db->close();