Results 1 to 6 of 6

Thread: PHP form data not populating table

  1. #1
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default PHP form data not populating table

    I need to populate user input on this form to a table, "registrations". I inserted some INSERT TO code (used w3c example as reference). I'm not getting any errors, but it's not populating the table with the information. INSERT TO code begins with $con below.

    Code:
    <?php
    print_r($_POST);
    
    {   
     if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']=="")||($_POST['giss1']=="")||($_POST['giss2']==""))
     {
      echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
      if($_POST['college'] == ""){ echo "<li>*College</li>"; }
      if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
      if($_POST['city'] == ""){ echo "<li>*City</li>"; }
      if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
      if($_POST['state'] == ""){ echo "<li>*State</li>"; }
      if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
      if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
      if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
      if($_POST['session'] == "unchecked") { echo "<li>You must select a GISS session</li>"; }
    echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
     }
     
     if ($selected_radio == 'giss1') {
    $giss1_status = 'checked';
    }
    else if ($selected_radio == 'giss2') {
    $giss2_status = 'checked';
    }
     
     if(isset($_POST['submit'])) {
    
        $to = "me@email.com"; 
        $subject = "Contact Has Registered";
        $college = $_POST['college'];
        $streetaddress = $_POST['streetaddress'];
        $city = $_POST['city'];
        $state = $_POST['state'];
    	$zip = $_POST['zip'];
        $contactperson = $_POST['contactperson'];
        $contactemail = $_POST['contactemail'];
    	$phone = $_POST['phone'];
    $selected_radio = $_POST['session'];
    print $session;
    }    
        $body = "From:$college
        Street Address:$streetaddress
    	City:$city
    	State:$state
    	Zip Code:$zip
        E-Mail:$contactemail
        Phone Number:$phone
        Contact Email:$contactemail
        GISS Session:$selected_radio";
        
        mail($to, $subject, $body);     
    
    $sendto = $_POST['contactemail']; 
    $ccto = "me@email.com"; 
    $subject = "Registration"; 
    $message = "Thank you for registering";
    
    if(mail($sendto, $subject, $message, $header)) header("location: attendee.html"); 
    } 
    
    $con = mysql_connect("localhost","username","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("registrations", $con);
    
    $sql="INSERT INTO attendee_registrants (college, street_address, city, state, zip, contact_person, contact_email, phone, fax, session)
    VALUES
    ('$_POST[college]','$_POST[streetaddress]','$_POST[city]'$_POST[state]','$_POST[zip]','$_POST[contactperson]','$_POST[contactemail]','$_POST[phone]','$_POST[fax]','$_POST[session]')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    
    ?>
    <script type=text/javascript>
    setTimeout("location.href='index.html'", [3000]);
    </script>

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    If you echo $sql; is the statement appearing as you'd expect it to (with the values)?

    You also may want to use javascript for the validation that all fields are entered, but that's something else...
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for responding.

    Nothing's appearing at all. I originally had the form working to just send the confirmation emails and later added in the INSERT TO. The form is still behaving as though I never entered that extra code, so nothing is different.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The blankness than is from an error(s) with your php. I've rewritten parts of your code and put in notes.

    PHP Code:
    <?php
    print_r
    ($_POST);
    if(
    $_POST['college']==""||$_POST['streetaddress']==""||$_POST['city']==""||$_POST['zip']==""||$_POST['state']==""||$_POST['contactperson']==""||$_POST['contactemail']==""||$_POST['phone']==""||$_POST['fax']==""||$_POST['giss1']==""||$_POST['giss2']=="") {
     
    ?>
     <html>
     <body>
     <p>The following fields are <strong>required</strong>.</p>
     <ul>
     <?php
     
    if($_POST['college'] == ""){ echo "<li>*College</li>"; }
     if(
    $_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
     if(
    $_POST['city'] == ""){ echo "<li>*City</li>"; }
     if(
    $_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
     if(
    $_POST['state'] == ""){ echo "<li>*State</li>"; }
     if(
    $_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
     if(
    $_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
     if(
    $_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
     if(
    $_POST['session'] == "unchecked") { echo "<li>You must select a GISS session</li>"; }
    ?>
    </ul>
    <p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p>
    </body>
    </html>
    <?php 
    if ($selected_radio == 'giss1') {
        
    $giss1_status 'checked';
    } else if (
    $selected_radio == 'giss2') {
        
    $giss2_status 'checked';
    }
    if(isset(
    $_POST['submit'])) {
        
    $to "me@email.com"
        
    $subject "Contact Has Registered";
        
    $college $_POST['college'];
        
    $streetaddress $_POST['streetaddress'];
        
    $city $_POST['city'];
        
    $state $_POST['state'];
        
    $zip $_POST['zip'];
        
    $contactperson $_POST['contactperson'];
        
    $contactemail $_POST['contactemail'];
        
    $phone $_POST['phone'];
        
    $selected_radio $_POST['session'];
        
    $fax $_POST['fax'];
    //print $session; session is never set and you don't need to print it
        
    echo $selected_radio;// remove this if using header.
    //} why close the if here? 
        
    $body "From:$college\nStreet Address:$streetaddress\nCity:$city\nState:$state\nZip Code:$zip\nE-Mail:$contactemail\nPhone Number:$phone\nContact Email:$contactemail\nGISS Session:$selected_radio";
        
    mail($to$subject$body);
    $sendto $_POST['contactemail']; 
    $ccto "me@email.com"
    $subject "Registration"
    $message "Thank you for registering";
    $header "From: me@me.com";
    // this is jambled are you trying to redirect them if the email is sent? this can't be achieved because you are echoing the selected radio and printing the posts above there are also missing brackets
    //assuming you dont echo selected radio and print the posts though...
    if (mail($sendto$subject$message$header)) {
        
    header("location: attendee.html"); 

    $con mysql_connect("localhost","username","password");
    if (!
    $con) {
        die(
    'Could not connect: ' mysql_error());
    }
    mysql_select_db("registrations"$con);

    $sql="INSERT INTO attendee_registrants (college, street_address, city, state, zip, contact_person, contact_email, phone, fax, session) VALUES ('$college','$streetaddress','$city'$state','$zip','$contactperson','$contactemail','$phone','$fax','$selected_radio')";
    if (!
    mysql_query($sql,$con)) {
        die(
    'Error: ' mysql_error());
    }
    mysql_close($con);
    ?>
    1 record added
    <?php
    }
    ?>
    <script type=text/javascript>
    setTimeout("location.href='index.html'", [3000]);
    </script>
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for putting in the time to edit my code

    The parts you noted for correction are functioning/were functioning fine (confirmation emails). I tried to remove/alter the options you suggested and got T_variable errors. It's the INSERT TO stuff that's not working. The form is sending correctly and confirmation emails are sending fine with the code I posted. I'm not getting any errors as-is. The table's just not populating.

  6. #6
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Replace
    Code:
    $sql="INSERT INTO attendee_registrants (college, street_address, city, state, zip, contact_person, contact_email, phone, fax, session)
    VALUES
    ('$_POST[college]','$_POST[streetaddress]','$_POST[city]'$_POST[state]','$_POST[zip]','$_POST[contactperson]','$_POST[contactemail]','$_POST[phone]','$_POST[fax]','$_POST[session]')";
    with

    Code:
    $sql="INSERT INTO attendee_registrants (college, street_address, city, state, zip, contact_person, contact_email, phone, fax, session)
    VALUES
    ('$_POST[college]','$_POST[streetaddress]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[contactperson]','$_POST[contactemail]','$_POST[phone]','$_POST[fax]','$_POST[session]')";

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •