Form -> mySQL, html email, and html output page?
Posted: Sat Feb 08, 2003 2:36 am
Hi, I'm pretty new at both PHP and mySQL, mostly patching together bits of knowledge from looking at how other scripts are put together, so it won't be surprising to me if I find I haven't done things the best way to start with... anyway, I have the following situation with which I need some guidance:
I have an html form, which users will complete and submit. When they hit "submit" I want the form data added to a mySQL database, and I want the data displayed in a web page, with a particular layout, including tables, graphics, etc... This part I've managed so far by having the form "post" to a php page that includes php code to add the data to the database:
...and uses <? php echo $field;> in the html code that follows to create the html formatted webpage that displays the data (and some other stuff).
These parts are working fine (if not the most elegant solution). However, I would also like to have the same data, also formatted in html, sent to the submitter in an email.
Is there some snippet of code I can add to this existing page that will do this? Do I need to rework the code completely? Or do I need a separate page?
Any guidance you can offer this newbie is greatly appreciated.
Thanks,
Sinemac
I have an html form, which users will complete and submit. When they hit "submit" I want the form data added to a mySQL database, and I want the data displayed in a web page, with a particular layout, including tables, graphics, etc... This part I've managed so far by having the form "post" to a php page that includes php code to add the data to the database:
Code: Select all
<?PHP
if ($submit == "Submit Assessment")
{
$db = mysql_pconnect("localhost", "xxxx", "yyyy");
if (!$db) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
mysql_select_db("my_database", $db);
$sql = ("INSERT INTO my_table (Cust_Name,Cust_Co,Cust_Email,Cust_Phone,Referral,
Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10,Q11,Q12) VALUES ("$Cust_Name","$Cust_Org","$Cust_Email","$Cust_Phone",
"$Referral","$Q1","$Q2","$Q3","$Q4","$Q5","$Q6","$Q7",
"$Q8","$Q9","$Q10","$Q11","$Q12");");
$result = mysql_query($sql, $db);
}
?>These parts are working fine (if not the most elegant solution). However, I would also like to have the same data, also formatted in html, sent to the submitter in an email.
Is there some snippet of code I can add to this existing page that will do this? Do I need to rework the code completely? Or do I need a separate page?
Any guidance you can offer this newbie is greatly appreciated.
Thanks,
Sinemac