Page 3 of 3
Re: Please Help - why is my data not writing to the table?
Posted: Tue Jun 15, 2010 5:01 pm
by ummhasan
ok thanks, here's the code to the form
[text] <form id="registration" name="registration" method="post" action="regConfirmation.php">
<table border="0" align="center" cellpadding="5" cellspacing="0" summary="Inheritors of the Prophets Ilm Competition registration form.
">
<tr align="center">
<th colspan="9" scope="col">Inheritance of the Prophets ILM Competition - Registration Form</th>
</tr>
<tr align="center">
<td colspan="9">for partner registration please complete both sections</td>
</tr>
<tr>
<td colspan="9" align="left"><strong><u>Participant 1</u></strong></td>
</tr>
<tr align="left">
<td width="113">Full Name</td>
<td width="148"><input name="name1" type="text" id="name1" accesskey="enter" tabindex="1" size="25" maxlength="100" /></td>
<td width="72" colspan="2">Phone Number</td>
<td width="33" colspan="3"><input name="ph1" type="text" id="ph1" accesskey="enter" tabindex="2" value="(###) ###-####" size="15" maxlength="15" /></td>
<td width="65">DOB</td>
<td width="126"><input name="dob1" type="text" id="dob1" accesskey="enter" tabindex="3" value="MM/DD/YYYY" size="10" maxlength="10" /></td>
</tr>
<tr align="left">
<td>Parent's Name</td>
<td><input name="parentName1" type="text" id="parentName1" accesskey="enter" tabindex="4" size="25" maxlength="100" /></td>
<td colspan="2">Parent's Email</td>
<td colspan="5"><input name="email1" type="text" id="email1" accesskey="enter" tabindex="5" size="35" /></td>
</tr>
<tr align="left">
<td>Address</td>
<td><input name="address1" type="text" id="address1" accesskey="enter" tabindex="6" size="25" maxlength="100" /></td>
<td width="72">City </td>
<td colspan="2"><input name="city1" type="text" id="city1" accesskey="enter" tabindex="7" size="20" maxlength="50" /></td>
<td width="39">State </td>
<td width="31"><input name="state1" type="text" id="state1" value="MI" size="2" /></td>
<td> Zip Code</td>
<td><input name="zip1" type="text" id="zip1" accesskey="enter" tabindex="8" size="5" maxlength="5" /></td>
</tr>
<tr align="left">
<td colspan="9"><hr /></td>
</tr>
<tr>
<td colspan="9" align="left"><strong><u>Participant 2</u> (optional)</strong></td>
</tr>
<tr align="left">
<td>Full Name</td>
<td><input name="name2" type="text" id="name2" accesskey="enter" tabindex="9" size="25" maxlength="100" /></td>
<td colspan="2">Phone Number</td>
<td colspan="3"><input name="ph2" type="text" id="ph2" accesskey="enter" tabindex="10" value="(###) ###-####" size="15" maxlength="15" /></td>
<td>DOB</td>
<td><input name="dob2" type="text" id="dob2" accesskey="enter" tabindex="11" value="MM/DD/YYYY" size="10" maxlength="10" /></td>
</tr>
<tr align="left">
<td>Parent's Name</td>
<td><input name="parentName2" type="text" id="parentName2" accesskey="enter" tabindex="12" size="25" maxlength="100" /></td>
<td colspan="2">Parent's Email</td>
<td colspan="5"><input name="email2" type="text" id="email2" accesskey="enter" tabindex="13" size="35" /></td>
</tr>
<tr align="left">
<td>Address</td>
<td><input name="address2" type="text" id="address2" accesskey="enter" tabindex="14" size="25" maxlength="100" /></td>
<td>City </td>
<td colspan="2"><input name="city2" type="text" id="city2" accesskey="enter" tabindex="15" size="20" maxlength="50" /></td>
<td>State </td>
<td><input name="state2" type="text" id="state2" value="MI" size="2" /></td>
<td> Zip Code</td>
<td><input name="zip2" type="text" id="zip2" accesskey="enter" tabindex="16" size="5" maxlength="5" /></td>
</tr>
<tr align="left">
<td colspan="9"><hr /></td>
</tr>
<tr align="left">
<td colspan="9"><strong>Select which level you are registering for </strong>(according to age as of July 31st, 2010)</td>
</tr>
<tr>
<td colspan="2" align="left"><label>
<input type="radio" name="levels" value="preE" />
Pre Elementary</label></td>
<td align="left"> </td>
<td colspan="3" align="left"><label>
<input type="radio" name="levels" value="elem" />
Elementary</label></td>
<td align="left"> </td>
<td colspan="2" align="left"><label>
<input type="radio" name="levels" value="inter" />
Intermediate</label></td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td align="left"> </td>
<td colspan="2" align="left"> </td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"><label>
<input type="radio" name="levels" value="junior" />
Junior</label></td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td colspan="3" align="left"><label>
<input type="radio" name="levels" value="senior" />
Senior</label></td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td colspan="3" align="left"> </td>
</tr>
<tr>
<!--onclick="MM_validateForm('name1','','R','ph1','','R','dob1','','R','parentName1','','R','email1','','RisEmail','address1','','R','city1','','R','state1','','R','zip1','','R','email2','','NisEmail');return document.MM_returnValue" value="Submit"-->
<td colspan="9" align="center"><input name="submit" type="submit" id="submit" accesskey="enter" tabindex="22" />
<input type="reset" name="reset" id="reset" value="Reset" accesskey="enter" tabindex="23" /></td>
</tr>
</table>
</form>
[/text]
Re: Please Help - why is my data not writing to the table?
Posted: Tue Jun 15, 2010 5:06 pm
by andyhoneycutt
Well then, try this out:
Code: Select all
<form id="registration" name="registration" method="post" action="regConfirmation.php">
<table border="0" align="center" cellpadding="5" cellspacing="0" summary="Inheritors of the Prophets Ilm Competition registration form.">
<tr align="center">
<th colspan="9" scope="col">Inheritance of the Prophets ILM Competition - Registration Form</th>
</tr>
<tr align="center">
<td colspan="9">for partner registration please complete both sections</td>
</tr>
<tr>
<td colspan="9" align="left"><strong><u>Participant 1</u></strong></td>
</tr>
<tr align="left">
<td width="113">Full Name</td>
<td width="148"><input name="name1" type="text" id="name1" accesskey="enter" tabindex="1" size="25" maxlength="100" /></td>
<td width="72" colspan="2">Phone Number</td>
<td width="33" colspan="3"><input name="ph1" type="text" id="ph1" accesskey="enter" tabindex="2" value="(###) ###-####" size="15" maxlength="15" /></td>
<td width="65">DOB</td>
<td width="126"><input name="dob1" type="text" id="dob1" accesskey="enter" tabindex="3" value="MM/DD/YYYY" size="10" maxlength="10" /></td>
</tr>
<tr align="left">
<td>Parent's Name</td>
<td><input name="parentName1" type="text" id="parentName1" accesskey="enter" tabindex="4" size="25" maxlength="100" /></td>
<td colspan="2">Parent's Email</td>
<td colspan="5"><input name="email1" type="text" id="email1" accesskey="enter" tabindex="5" size="35" /></td>
</tr>
<tr align="left">
<td>Address</td>
<td><input name="address1" type="text" id="address1" accesskey="enter" tabindex="6" size="25" maxlength="100" /></td>
<td width="72">City </td>
<td colspan="2"><input name="city1" type="text" id="city1" accesskey="enter" tabindex="7" size="20" maxlength="50" /></td>
<td width="39">State </td>
<td width="31"><input name="state1" type="text" id="state1" value="MI" size="2" /></td>
<td> Zip Code</td>
<td><input name="zip1" type="text" id="zip1" accesskey="enter" tabindex="8" size="5" maxlength="5" /></td>
</tr>
<tr align="left">
<td colspan="9"><hr /></td>
</tr>
<tr>
<td colspan="9" align="left"><strong><u>Participant 2</u> (optional)</strong></td>
</tr>
<tr align="left">
<td>Full Name</td>
<td><input name="name2" type="text" id="name2" accesskey="enter" tabindex="9" size="25" maxlength="100" /></td>
<td colspan="2">Phone Number</td>
<td colspan="3"><input name="ph2" type="text" id="ph2" accesskey="enter" tabindex="10" value="(###) ###-####" size="15" maxlength="15" /></td>
<td>DOB</td>
<td><input name="dob2" type="text" id="dob2" accesskey="enter" tabindex="11" value="MM/DD/YYYY" size="10" maxlength="10" /></td>
</tr>
<tr align="left">
<td>Parent's Name</td>
<td><input name="parentName2" type="text" id="parentName2" accesskey="enter" tabindex="12" size="25" maxlength="100" /></td>
<td colspan="2">Parent's Email</td>
<td colspan="5"><input name="email2" type="text" id="email2" accesskey="enter" tabindex="13" size="35" /></td>
</tr>
<tr align="left">
<td>Address</td>
<td><input name="address2" type="text" id="address2" accesskey="enter" tabindex="14" size="25" maxlength="100" /></td>
<td>City </td>
<td colspan="2"><input name="city2" type="text" id="city2" accesskey="enter" tabindex="15" size="20" maxlength="50" /></td>
<td>State </td>
<td><input name="state2" type="text" id="state2" value="MI" size="2" /></td>
<td> Zip Code</td>
<td><input name="zip2" type="text" id="zip2" accesskey="enter" tabindex="16" size="5" maxlength="5" /></td>
</tr>
<tr align="left">
<td colspan="9"><hr /></td>
</tr>
<tr align="left">
<td colspan="9"><strong>Select which level you are registering for </strong>(according to age as of July 31st, 2010)</td>
</tr>
<tr>
<td colspan="2" align="left"><label>
<input type="radio" name="levels" value="preE" />
Pre Elementary</label></td>
<td align="left"> </td>
<td colspan="3" align="left"><label>
<input type="radio" name="levels" value="elem" />
Elementary</label></td>
<td align="left"> </td>
<td colspan="2" align="left"><label>
<input type="radio" name="levels" value="inter" />
Intermediate</label></td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td align="left"> </td>
<td colspan="2" align="left"> </td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"><label>
<input type="radio" name="levels" value="junior" />
Junior</label></td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td colspan="3" align="left"><label>
<input type="radio" name="levels" value="senior" />
Senior</label></td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"> </td>
<td colspan="3" align="left"> </td>
<td colspan="3" align="left"> </td>
</tr>
<tr>
<!--onclick="MM_validateForm('name1','','R','ph1','','R','dob1','','R','parentName1','','R','email1','','RisEmail','address1','','R','city1','','R','state1','','R','zip1','','R','email2','','NisEmail');return document.MM_returnValue" value="Submit"-->
<td colspan="9" align="center"><input name="submit" type="submit" id="submit" accesskey="enter" tabindex="22" />
<input type="reset" name="reset" id="reset" value="Reset" accesskey="enter" tabindex="23" /></td>
</tr>
</table>
</form>
<?php
if(isset($_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.";
}
else
{
//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'];
/**
* Array, instead of a switch:
*/
$table_to_insert_to = array("preE" => "pre_elementary",
"elem" => "elementary",
"inter" => "intermediate",
"junior" => "junior",
"senior" => "senior");
$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.
$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());
}
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>";
}
}
Re: Please Help - why is my data not writing to the table?
Posted: Tue Jun 15, 2010 5:20 pm
by ummhasan
Thanks again, before I try it, I noticed that you have everything in one page. Maybe this is my problem.
I have one page for my form (an html document) and then one page that the form action calls (a php document) and they are separate.
Should I combined them or keep them separate or does it not matter?
I think I MUST have them separate for it to actually call the action page right?
Re: Please Help - why is my data not writing to the table?
Posted: Tue Jun 15, 2010 9:00 pm
by ummhasan
OK, i added the new code to my php page and left the html seperate, now, it seems i'm only having some validation issues. I only have the error:
You have not entered all the required information. Please go back and fully complete the form.You have chosen to enter without a partner - if you change your mind, please contact us.
Which is my echo statements if validation fails - BUT all fields are filled out. I will take another look over the opening and closing braces and see if I made a mistake there.
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 5:20 am
by ummhasan
ok, i cleaned up the code some, added some additional validation, some else and else if's and now all i'm getting is this:
Parse error: syntax error, unexpected $end in /home/content/u/m/m/ummhasan/html/ilmComp/regConfirmation.php on line 135
her's the code..............line 135 is the last line
Code: Select all
<?php
//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'];
if(isset($_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 && !name2)
{
echo "You have not entered all the required information. " .
"Please go back and fully complete the form.";
} elseif ($name2 && !$ph2 || !$dob2 || !$parentName2 || !$email2 || !$address2 || !$city2 || !$state2 || !$zip2)
{
echo "Your have not entered all of your partners 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
{
/**
* Array, instead of a switch:
*/
$table_to_insert_to = array("preE" => "pre_elementary",
"elem" => "elementary",
"inter" => "intermediate",
"junior" => "junior",
"senior" => "senior");
$con = new PDO("mysql:host=ilmcompetition.db.2695729.hostedresource.com;dbname=ilmcompetition", ilmcompetition, Bismilla2552)
or
die("Couldn't connect to specificied datasource.");
// Create a tokenized query string to pass to our statement object.
$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,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zipcode2" => $zip2,
"phone2" => $ph2,
"dob2" => $dob2,
"parent2" => $parentName2,
"email2" => $email2));
if( !$my_result )
{
print_r($con->errorInfo());
} 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 choosen to enter without a partner - if you change your mind, please contact us.</td></tr></table>";
}
}
?>
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 8:03 am
by ummhasan
ok, it must be the way my if else if else statements are constructed but I dont see anything wrong. Do you?
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 9:09 am
by andyhoneycutt
Your indentation is a little off, which probably lead to the missing } at the end. You need to add another end brace to close out the if(isset($_POST['submit']))
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 9:44 am
by ummhasan
sorry.........i forgot to mention that I already noticed that and added it. I also noticed that the array hadd curly braces instead of parens so I changed that too......heres the changed code oh and I will include everything around the php this time maybe that has something to do with it.
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inheritance of the Prophets - Ilm Competition</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body class="oneColFixCtr">
<div id="container">
<div id="mainContent">
<h1 id="welcome">Inheritance of the Prophets ILM Competition</h1>
<div class="nav"><a href="index.html">Home</a> | <a href="information.html">Information</a> | <a href="register.html">Registration</a> | <a href="studyguide.htm">Study Materials </a>| <a href="faq.html">FAQ</a> | <a href="contactus.html">Contact Us</a></div>
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_registration = "my_host";
$database_registration = "my_database";
$username_registration = "user_name";
$password_registration = "my_password";
$con = new PDO("$hostname_registration;dbname=ilmcompetition", $username_registration, $password_registration)
or
die("Couldn't connect to specificied datasource.");
//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'];
if(isset($_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 && !name2)
{
echo "You have not entered all the required information. Please go back and fully complete the form.";
} elseif ($name2 && !$ph2 || !$dob2 || !$parentName2 || !$email2 || !$address2 || !$city2 || !$state2 || !$zip2)
{
echo "Your have not entered all of your partners 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
{
/**
* Array, instead of a switch:
*/
$table_to_insert_to = array("preE" => "pre_elementary",
"elem" => "elementary",
"inter" => "intermediate",
"junior" => "junior",
"senior" => "senior");
// Create a tokenized query string to pass to our statement object
$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,
"phone" => $ph1,
"dob" => $dob1,
"parent" => $parentName1,
"email" => $email1,
"name2" => $name2,
"address2" => $address2,
"city2" => $city2,
"state2" => $state2,
"zipcode2" => $zip2,
"phone2" => $ph2,
"dob2" => $dob2,
"parent2" => $parentName2,
"email2" => $email2));
if( !$my_result )
{
print_r($con->errorInfo());
} 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 choosen to enter without a partner - if you change your mind, please contact us.</td></tr></table>";
}
}
}
$con = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</div>
</div>
</body>
</html>
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 10:13 am
by andyhoneycutt
Your catch block is invalid. Proper catch would be:
Code: Select all
try
{
// do something
}
catch(Exception $e)
{
print_r($e);
}
My guess would be that it's causing an error just sitting there...
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 10:30 am
by ummhasan
I deleted the catch block and still get the same error
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 10:39 am
by andyhoneycutt
After modifying your code to attach to databases that I have, I get no errors at all when running your code. No syntax or compile-time errors...
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 11:02 am
by ummhasan
heeeemmm
Well then i guess i have to contact my host to see what might be going on.
Thanks a lot for all of your time and help and teaching! I really appreciate it!
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 11:13 am
by andyhoneycutt
You're welcome. I hope you are able to solve this one. If you find a solution, come back and post it if you would be so kind!
Good Luck!
Re: Please Help - why is my data not writing to the table?
Posted: Wed Jun 16, 2010 5:18 pm
by ummhasan
Ok, well, there was a missing bracket but even after fixing that, I found out that my host does NOT allow a pdo connection because i'm on a shared server.
So that means that I have to put back in the remove slashes, and change some of the program.
ARGGGGGHHHHH