Jump to content

insert into database then invoke formmail.php?


slanderman

Recommended Posts

need some help.

 

I've got a webform that emails form data to me when the user clicks submit. I'm also wanting to store this form data in a database.

 

I've done a little research on the web and the best suggestion ive seen so far suggests to call the database php app from the webform and have the database app invoke formmail to email the data after storing it in the database. The code below is what i'm working with to store the data in the database, but I'm not sure how to make the code invoke the other php app when its done with the database procedures. The other php app is called formmail.php

 

If anyone could please help me I'd really appreciate it.

 

 

 

<?php
$con = mysql_connect("xxx.xxx.xxx.xxx","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="INSERT INTO tablename (firstname, lastname, email, performername1, performername2)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[performername1]','$_POST[performername2]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

mysql_close($con)
?>

You could send mail after inserting as simply as

 

<?php
$con = mysql_connect("xxx.xxx.xxx.xxx","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="INSERT INTO tablename (firstname, lastname, email, performername1, performername2)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[performername1]','$_POST[performername2]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

$message = "Combine your data fields";

mail('youremail', 'subject of email', $message);

mysql_close($con)
?>

 

If you want to use formmail.php, just put your code in to insert to the database right above the mail() line in formmail.php

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.