I have just created a simple form script but it does not work. when I fill in the text boxes and click submit it does not put anything in the database and brings up the same form page again (with no text in it) instead pof bringing up the thank you page.
The php script is as follows:
<?php require_once("connect/connection.php");
require_once("includes/functions.php");
if(isset($_POST['submit'])){
$errors = array();
$requiredfields = array('first_name'=> 'Please enter your FIRST NAME','surname'=> 'Please enter your SURNAME','email'=> 'Please enter your E Mail ADDRESS','text'=> 'Please enter your current needs');
foreach($requiredfields as $fieldname => $requiredfieldsmessage){
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) {
$errors[] = $requiredfieldsmessage;
}
}
if(count($errors) == 0){
$_POST = array_map('mysqli_prep', $_POST);
$first_name = mysqli_prep($_POST['first_name']);
$surname = mysqli_prep($_POST['surname']);
$email = mysqli_prep($_POST['email']);
$text = mysqli_prep($_POST['text']);
$query = "INSERT INTO contact_form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
$result = mysqli_query($connection, $query);
header('Location: brief_return.php');
exit;
}
}
?>
Can you clarify what you mean by normal variables? and where you think i’m going wronmg? I don’t understand where I am going wrong. I adapted this form from one that is working perfectly and has {}.