Jump to content


Photo

Form help


  • Please log in to reply
6 replies to this topic

#1 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 13 July 2006 - 03:23 AM

I was wondering if it is possible to insert data from a form into my database and have the data be sent via email at that same time? I have no trouble doing either on there own, but combining the two is where I'm lost.

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 July 2006 - 03:28 AM

well yes,
you insert data into database,
then after that, compose an email and send.
Life's too short for arguing.

#3 gewthen

gewthen
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 13 July 2006 - 03:36 AM

I was wondering if it is possible to insert data from a form into my database and have the data be sent via email at that same time? I have no trouble doing either on there own, but combining the two is where I'm lost.


Yes, it possible to insert data into a database and email what it inserted within the same script. You might have an SQL statement:

<?php
$sql="INSERT INTO
         myTable 
        (id, name, address, city, state, zip) 
       VALUES(null, '".$name."', '".$address."', 
        '".$city."', '".$state."', '".$zip."' )";

mysql_query($sql);
?>

All you need is to send the mail (assuming your PHP has mailing enabled).

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = "$name $address $city $state $zip";
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

The above was taken and then edited from php.net.

The above should insert the data into the database and send the values to you.

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 13 July 2006 - 03:54 AM

That's weird, I had tried that and it didn't work o_O. Works now though, must of been something wrong with my code. Thank you guys for your help.

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 July 2006 - 07:05 AM

Sorry to bring this thread back up. Got another question. Instead of composing the email on the same page, is there anyway to include it from another file as I would if I were sending it on a contact form? Then reason is, I want it to display a confirmation. I know I could have it display a confirmation on that page but, it would also include the form they just filled out. I just want a confirmation of the information they just filled in for them to print.

#6 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 16 July 2006 - 01:35 AM

bump

#7 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 16 July 2006 - 11:37 AM

Sorry to keep bumping this, but does anyone have any suggestions?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users