pgrevents Posted June 10, 2009 Share Posted June 10, 2009 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 More sharing options...
pgrevents Posted June 10, 2009 Author Share Posted June 10, 2009 nevermind i forgot the auto increment on the new mysql database feel free to shoot Link to comment https://forums.phpfreaks.com/topic/161743-simple-contact-form-error/#findComment-853389 Share on other sites More sharing options...
elis Posted June 10, 2009 Share Posted June 10, 2009 If you haven't already, you might want to consider sanitizing your $_POSTs and $_GETs as well as doing validation that they fields contain what they should contain. Link to comment https://forums.phpfreaks.com/topic/161743-simple-contact-form-error/#findComment-853390 Share on other sites More sharing options...
pgrevents Posted June 10, 2009 Author Share Posted June 10, 2009 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 Link to comment https://forums.phpfreaks.com/topic/161743-simple-contact-form-error/#findComment-853393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.