Results 1 to 3 of 3

Thread: Can i both insert form data in an sql db AND email the contents at the same time?

  1. #1
    Join Date
    Jul 2003

    Question Can i both insert form data in an sql db AND email the contents at the same time?

    Hello and thank you for providing a great forum. I have an issue re: submitting a form that i need help with.

    I have an HTML form that currently writes to a MySQL db using when the user hits 'Submit'. The PHP code looks like so:

    if (isset($_REQUEST['submit']))
    mysql_query("INSERT INTO table_name(field1, field2) VALUES ('" .
    $_REQUEST['firstname'] ."','" . $_REQUEST['lastname'] . "')");

    this functionality works fine. is there a way to also email the form to several people when the user 'Submits'?

    Any help is aprecciated. Thanks in advance.

  2. #2
    Join Date
    Mar 2003
    You can e-mail the information using the mail() command.

    If all the data you need is already 'in' the PHP page, then its easy - would look something like this...

    mail($emailto, $subject, $mailmessage, $headers);

    or if you want just to send the same message every time, you could include the relevant stuff directly like this

    mail("harrypotter@hogwarts.com","New Magi-viagra","Use our new product and never have your wand let you down again!");

    The headers part is optional, but if you wanted to make your message HTML then you would need to include some headers in there. For more on that, there is a post a couple of weeks back which will tell you about that - because I had a question on it and got some really useful replies.

    If you need to get data out of the database to send in your e-mail, you would need to do a bit more. Like, say you are storing data with a unique ID which is auto-incremented...and you want to quote that ID number in the mai - after you add the new data, you would then need to re-interrogate the DB to get the id of the entry you just created. Like this

    $result = mysql_query("SELECT max(id_num) FROM my_database");


    $the_id_num= $row[0];

    Then you can include $the_id_num in your message too. Etc..

    Hope that made sense... good luck.
    Last edited by tobyw_1969; 07-20-2003 at 12:12 PM.

  3. #3
    Join Date
    Jul 2003
    Thanks for the quick response. I don't know why i didn't think of this

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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