Contact form that sends to email and also MySQL

Discussion in 'Web Design and Development' started by jdl8422, Jun 19, 2008.

  1. jdl8422 macrumors 6502

    jdl8422

    Joined:
    Jul 5, 2006
    Location:
    Louisiana
    #1
    well I have an online survey I am doing for my company. Currently the page is in html/css and the form is in php. I have it to where it sends the data to an email. I would also like for it to go to a MySQL database as well as the email. Other than setting the database up on the server, what code would I need to get it to go to both. Also, I am not here looking for someone to do it for me:D. I just need some direction. Thanks in advance.
     
  2. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #2
    Code:
    $tableName = formData; //this is the name of the table in the DB
    
    //your post data...
    $name = $_POST['NAME'];
    $phone = $_POST['PHONE'];
    $addy = $_POST['ADDY'];
    
    //the actual SQL
    $sql = "INSERT INTO $TableName (NAME,PHONE, ADDY) VALUES ('$name', '$phone', '$addy')";
    
    $result = mysql_query($sql); //define a var for the query for simplicity sake
    $response = ($result) ?  'Entry Added' : 'Entry FAILED!'; //test to see if the query was successful to replay a message back to the user... 
    echo $response; // print the message back to the user, this is also required to execute the query... 
    
    I haven't tested any of that, I just wrote it off the top of my head, but that should work...
     
  3. jdl8422 thread starter macrumors 6502

    jdl8422

    Joined:
    Jul 5, 2006
    Location:
    Louisiana
    #3
    Once I have the database set up and the emails go to it, can I input my current emails to it?
     
  4. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #4
    yes, there is no reason you shouldnt be able to...
     

Share This Page