SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Searching good documentation about - contact form to e-mail and database

    Hello,

    I've a form that sends data to and e-mail. However, the request is that the form data also get stored on the database.

    I know how to do one. I know how to the the other.

    How can we do both?

    Please, anything just to start digging...


    Regards,
    Marcio

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do one after the other: mailing first and saving to db next?
    example:
    PHP Code:
    if(isset($_POST['submit']))
    {
    //data valiation
    //compose email
    mail($to$subject$body,$headers);

    //now do the database stuff
    $db mysql_connect("servername","username","password");
       if(!
    $db) die("Error connecting to MySQL database.");
       
    mysql_select_db("databasename" ,$db);

     
    $sql "INSERT INTO contacts (name, email) VALUES (".
             
    PrepSQL(name) . ", " .
             
    PrepSQL($email")";
    mysql_query($sql);

    //redirect to thank you page
    header('Location: thank-you.html');


    More Info:
    PHP form processing

    HTML contact form with CAPTCHA

  3. #3
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot.

    One last strange question:

    Are there any inconvenience to the fact that the form submit to itself?

    Regards,
    Márcio

  4. #4
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forget my last post.


    I got it. It's actually not even an issue then.

    But thanks for your post. If it wasn't for him, maybe I would still asking myself, "how to do both"


    Regards,
    Márcio


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
  •