hi,
I have recently created a form. everything works fine except for the fact that it places two sets of correct data into the database instead of one, once the submit button is clicked.
Below is the relevant php:
<?php require_once("includes/connection.php");
include("includes/functions.php");
//form validation
if(isset($_POST['submit'])){
$errors=array();
$requiredfields=array('site_use'=>'Please enter web site type','biz_type'=>'Please enter your business details','market'=>'Please enter the market question','style'=>'Please answer the style question If not sure just put unsure','message'=>'Please answer the message question If not sure just put unsure','branding'=>'Please answer the branding question If not sure put unsure','budget'=>'Please enter a budget figure','images'=>'Please state if you can provide images','name'=>'Please enter your name','email'=>'Please enter your email so we can contact you','aftercare'=>'Please state if you are wish to have aftercare services');
foreach($requiredfields as $fieldname => $requiredfieldsmessage){
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) /*|| $_POST[$fieldname]==""*/ {
$errors[] = $requiredfieldsmessage;
}
}
if(count($errors) == 0){
$_POST = array_map('mysqli_prep', $_POST);
//end form validation
$name = mysqli_prep($_POST['name']);
$email = mysqli_prep($_POST['email']);
$tel = mysqli_prep($_POST['tel']);
$site_use = mysqli_prep($_POST['site_use']);
$biz_type = mysqli_prep($_POST['biz_type']);
$market = mysqli_prep( $_POST['market']);
$style = mysqli_prep( $_POST['style']);
$message = mysqli_prep($_POST['message']);
$branding = mysqli_prep($_POST['branding']);
$budget = mysqli_prep($_POST['budget']);
$images = mysqli_prep($_POST['images']);
$aftercare = mysqli_prep($_POST['aftercare']);
$query = "INSERT into briefing_form (
name,email,tel,site_use,biz_type,market,style,message,branding,budget,images,aftercare)Values('{$name}','{$email}','{$tel}','{$site_use}','{$biz_type}','{$market}','{$style}','{$message}','{$branding}','{$budget}','{$images}','{$aftercare}')";
$result = mysqli_query($connection, $query);
$message="You have recieved a briefing form";
$subject="briefing form";
$subject2="Your Quote";
$message2="Thank you for contacting us. We will forward a quote to this address.";
$email2=$email;
mail('*****',$subject,$message);
mail($email2, $subject2, $message2);
$result = mysqli_query($connection, $query);
header("Location: http://www.mysite/brief_return.php");
exit;
}
}
?>
and a snippet from the form:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><td style="padding:20px">
<p >What is your type of business, what are are your products and/or services?</p>
<textarea name="biz_type" cols="40" rows="5" > <?php echo htmlspecialchars($_POST['biz_type'],ENT_QUOTES); ?></textarea></td>
</tr>
Anyone any ideas why the form is doing this?
thanks