nagger Posted February 8, 2009 Share Posted February 8, 2009 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 = '[email protected]'; $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()); }</body> Link to comment https://forums.phpfreaks.com/topic/144359-submit-form-to-mysql-email/ Share on other sites More sharing options...
Fahid Posted February 8, 2009 Share Posted February 8, 2009 Try changing the following portion better try copy/paste <?php $db = 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)) { die("Database Error". mysql_error()); //$_POST['SQL_query_result'] = 'Database Error'; } ?> Link to comment https://forums.phpfreaks.com/topic/144359-submit-form-to-mysql-email/#findComment-757537 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.