Jump to content

Simple Contact Form Error


pgrevents

Recommended Posts

The below code does not save to the database. Now this is the final stage of the deployment of the site and I only discovered this error when uploading to the website. On my testing server it works fine. But on the live server it prints an error and does not add to database.

 

The site is run on mysql data from individual pages to image locations and all of those work except this insert statement uses the same connection??

 

Can anyone shed some light

 

<?php
// CONTACT FORM
    if(isset($_POST['submit'])){
// GRAB DATA
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// SET DATE AND TIME
$date = date('d/m/Y');
$time = date('h:i');
// FIRST SAVE TO DATABASE
$dbhost = 'SERVERNAME';
$dbuser = 'DBUNAME';
$dbpass = 'DBPASS';
$dbname = 'DBNAME';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
if(mysql_query("INSERT INTO contact (name, email, message, time, date) VALUES ('$name', '$email', '$message',    '$time', '$date')")){
// NOW MAIL
$to      = 'EMAIL ADDRESS';
$subject = 'New Message From Contact Form';
$body    = "Massaged received at ".$time." on the ".$date."\n\n From: ".$name."\nEmail Address: ".$email."\n\n\nMessage;\n".$message."";
$headers = 'From: websiteaddress' . "\r\n" .
    			'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
//NOW REDIRECT USER
header('Location:../?id=553&sent');
}
else{
header('Location:../?id=553&error');	
}
}
else {
header('Location:../?id=553&error');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/161743-simple-contact-form-error/
Share on other sites

I do all my validation on the page i understand the security of the php file itself and stopping injections but its a small portfolio site and if spam becomes an issue I will implement that at a later date. I aint that strong at php so dont want to go down a route I dont know

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.