Hello,
I'm having an issue right now. Everything i click the complete registration page on this site.
https://www.encourageexcellence.org/registration.php
The values entered won't submit nor return any error messages. Could you show me what I'm doing wrong? Here is the code
<?php
if (isset($_POST['submitted'])){
require_once('Connections/encourage.php');
$fields = array(
'email',
'state',
'district',
'gender',
'age',
'profession',
);
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 (email, state, district, gender, age, profession, survey, registration_date)
VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey', 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);
}
?>
<!----html code-->
<form id="form1" name="form1" method="post" action"registration.php">
<fieldset class="first">
<label class="email" for="email">Email:* </label>
<input name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>"/>
<label for="state"/>State:* </label>
<input name="state" value="<?php if(isset($_POST['state'])) echo $_POST['state'];?>"/>
<label for="schooldistrict"/>School District:* </label>
<input name="district" value="<?php if(isset($_POST['district'])) echo $_POST['district'];?>" />
<label for="gender">Gender:* </label>
<select name="gender">
<option>Choose Your Gender</option>
<option value="male" <?php echo ($form['gender'] == 'male' ? ' selected' : ''); ?>>Male</option>
<option value="female"<?php echo ($form['gender'] == 'female' ? ' selected' : ''); ?>>Female</option>
</select>
<label for="age"/>Your Age:* </label>
<input name="age" type="text" class="age" maxlength="2" value="<?php if(isset($_POST['age'])) echo $_POST['age'];?>" />
<label for="profession"/>Profession:* </label>
<input name="profession" value="<?php if(isset($_POST['profession'])) echo $_POST['profession'];?>" />
<label for="survey"/>Willingness to participate in future surveys:</label>
<input name="survey" type="checkbox" value="Yes" />
</fieldset>
<fieldset>
<input name="submit" type="submit" class="btn1" value="Complete your Registration" />
<input class="btn" name="reset" type="reset" value="Clear Form" />
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
Thanks in advanced!