Hello,
I'm building a basic database. after the user hit next, i get a blank page and i don't see any data from the form to the databases table.
Here is the url to test.
http://encourageexcellence.org/registration.php
Here is the code:
<form id="form1" name="form1" method="post" action="thanks.php">
<fieldset class="first">
<label class="name" for="email">Name:* </label>
<input name="name" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>"/>
<label for="address"/>
Address:* </label>
<input name="address" value="<?php if(isset($_POST['address'])) echo $_POST['address'];?>"/>
<label for="city"/>
City:* </label>
<input name="city" value="<?php if(isset($_POST['city'])) echo $_POST['city'];?>"/>
<label for="state"/>
State:* </label>
<input name="state" value="<?php if(isset($_POST['state'])) echo $_POST['state'];?>" size="2" maxlength="2"/>
<label for="zip"/>
Zip:* </label>
<input name="zip" value="<?php if(isset($_POST['zip'])) echo $_POST['zip'];?>" size="5" maxlength="5"/>
<label for="email"/>
Email:* </label>
<input name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" />
<label for="phone"/>
Phone: </label>
<input name="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>" />
</fieldset>
<fieldset>
<input name="submit" type="submit" class="btn1" value="Next" />
<input class="btn" name="reset" type="reset" value="Clear Form" />
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
Here is the php code on the thanks.php page which it comes out blank
<?php
if (isset($_POST['submitted'])){
require_once('Connections/encourage.php');
$fields = array(
'name',
'address',
'city',
'state',
'zip',
'email',
'phone',
/*?>'age',
'profession',
<?php */
);
/*if (safe($_POST['survey']=="Yes")){
$survey = "Yes";
}
else{
$survey = "No";
}*/
foreach($fields as $fieldName) {
if(isset($_POST[$fieldName]) and safe(trim(stripslashes($_POST[$fieldName]))) !==''){
$$fieldName = safe(trim(stripslashes($_POST[$fieldName])));
}else {
$errors[] = "Please enter your". $fieldName .""; //code to validate fields
}
if(filter_var($email, FILTER_VALIDATE_EMAIL) == true){
} else {
$errors[] = 'Please enter a valid email address';
}
}
if(!isset($errors)){
$query = "SELECT user_id FROM participants WHERE email='$email'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 0) {
$query = "INSERT INTO participants (name, address, city, state, zip, email, phone, registration_date)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$email', '$phone', NOW())"; //databasse connection
$result = mysql_query ($query);
if ($result){
/*$url = 'http://'. $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') || (substr($url, -1) == '\\')) {
$url = substr ($url, 0, -1);
}*/
/*$url .= '/thanks.php';*/
header("Location: $url"); //This is the line of error that is reporting after submitting to the database
exit();
} else {
$errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.';
$errors[] = mysql_error() . '<br /><br />Query: ' . $query;
}
} else {
$errors[] = 'The email address has already been registered.';
}
}
mysql_close();
} else {
$errors = NULL;
}
if (!empty($errors)){
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach($errors as $msg) {
echo " - $msg<br/>\n";
}
echo '</p><p>Please try again.</p><p><br/></p>';
}
function safe($string)
{
$pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i";
return preg_replace($pattern, '', $string);
}
?>
The way my database is set up is
[ATTACH]5333[/ATTACH]
Let me know what am i doing wrong, please help, thanks!
databasestructure.JPG