Hi guys,
The code below is what I am using to try and submit the content of a form to a mysql database and also email the form results at the same time. Unfortunately it is doing neither! Can anyone shed any light on the problem please?
<?php
// sql
$con = mysql_connect("database.XXX.com","XXXXXX","XXXXXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("XXXXXXX_com_db", $con);$sql="INSERT INTO Enquiries (hear, name, email, contact, Schoolorcollege, date)
VALUES
('$_POST[hear]','$_POST[name]','$_POST[email]','$_POST[contact]','$_POST[Schoolorcollege]','$_POST[date]')";
$_POST['SQL_query_result'] = 'Success';
if (!mysql_query($sql,$con))
{
$_POST['SQL_query_result'] = 'Database Error';
}
// mail
$to = 'myemail@myemail.com';
$subject = 'Request Form';
$crlf = "\n";
$headers =
'MIME-Version: 1.0'.$crlf.
'From: '.$from.$crlf.
'Content-type: text/plain; charset=iso-8859-1'.$crlf;
foreach($_POST as $key => $val)
{
$key = str_replace('_', ' ', $key);
$message .= $key .' '. $val . $crlf;
}
mail($to, $subject, $message);
// confirm
if ($_POST['SQL_query_result'] = 'ok')
{
mysql_close($con);
header('Location: dbas/thanks.php');
exit;
}
else
{
die('Error: ' . mysql_error());
}