Please Help - why is my data not writing to the table?
Posted: Mon Jun 14, 2010 11:24 am
Hi, below is my code........can someone please tell me why the data is NOT writing to the mySQL table. I created the tables using myPHPadmin that's why create table is not in my code.
Thanks in advance - below is the code:
Thanks in advance - below is the code:
Code: Select all
$con = mysql_pconnect("my_host","my_user_name","my_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("ilmcompetition", $con);
if (!$db_selected)
{
die ("Can\'t use test_db : " . mysql_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];
//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);
}
//make short variable for radio buttons
$preE_status=$_POST[preE]; $elem_status=$_POST[elem]; $inter_status=$_POST[inter];
$junior_status=$_POST[junior]; $senior_status=$_POST[senior];
switch($levels)
{
case "preE":
$preE_status='checked';
$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);
break;
case "elem":
$elem_status='checked';
$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."')";
break;
case "inter":
$inter_status='checked';
$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;
case "junior":
$junior_status='checked';
$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;
case "senior":
$senior_status='checked';
$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.";
}
//checks for data results then displays results to user and confirms submission
//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>";
}
mysql_close($con);