Results 1 to 1 of 1

Thread: having php form data populate SQL database

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

    Default having php form data populate SQL database

    Thanks to everyone who puts up with my occasionally stupid queries.

    I have a form script that some of you may remember. I now need to populate user input on the 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>
    Last edited by kairick; 06-29-2010 at 02:00 PM. Reason: UPDATED

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
  •