Skip navigation
Currently Being Moderated

Form is not submitting to the databases

Aug 15, 2012 10:55 AM

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

 

 

[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>

 

[/CODE]

 

Thanks in advanced!

 

 

 
Replies
  • Currently Being Moderated
    Aug 15, 2012 11:18 AM   in reply to atlnycdude24

    The form HTML is incorrect.

     

      <form id="form1" name="form1" method="post" action"registration.php">

     

    you're missing a  = after action

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 12:03 PM   in reply to atlnycdude24

    You are also not asking it to connect to a database, your "action=registration.php" is telling it to connect to itself. That action should be going to your form processing script.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 12:17 PM   in reply to atlnycdude24

    I have never heard of a php form processing script that functions the way you describe. The form processing script is usually a separate entity stored on the server that is called into action by the form when info is sent to it.

     

    At least that's how every pre-made form script I've ever used has worked. Maybe you're just trying something that's way over my head. There's likely a php coder here somewhere that can help you get it running, might take a while to get your answer though.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2012 1:39 PM   in reply to atlnycdude24

    Yep, over my head.

     

     

    Have a good one.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points