Hi Guys, I wonder if you can help.
I have set up a form which then redirects to a thank you page in the way I normally would, but I am having a problem with users who are on IE 11 or Edge 1.0. There form submits over 10-20 times giving 10-20 duplicate results for them on the database table, as well as the user receiving 10-20 confirmation emails (which is more the problem)! As far as I can see from the stats the IE11 and Edge users are getting to the thank you page. Everyone else is submitting fine from other browsers.
Here is the PHP code I am using. Can anyone shed any light?
I have tried to do a header(‘Location: /thankyou.html/’); to try and instead to help but this didn’t work. I have tried replacing the submit on the html side to be an
button. Again still the same issue.
Any help gratefully received.
<?php
if (isset($_POST['add']))
{
include_once '../includes/db.inc.php';
try
{
$sql = 'INSERT INTO table SET
attending= :attending,
firstname= :firstname,
surname= :surname,
email= :email,
phone= :phone,
title= :title,
date = CURDATE()';
$s = $pdo->prepare($sql);
$s->bindValue(':attending', $_POST['attending']);
$s->bindValue(':firstname', $_POST['firstname']);
$s->bindValue(':surname', $_POST['surname']);
$s->bindValue(':email', $_POST['email']);
$s->bindValue(':phone', $_POST['phone']);
$s->bindValue(':title', $_POST['title']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error on submitting.';
include 'error.html.php';
exit();
}
/////give a ticket number
$userid = $pdo->lastInsertId();
$ticketnumber = 'CODE'.$userid;
try
{
$sql = 'UPDATE table SET
ticketnumber = :ticketnumber
WHERE id = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':ticketnumber', $ticketnumber);
$s->bindValue(':id', $userid);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error inputting ref number.';
include 'error.html.php';
exit();
}
////////////send email/////////////
$subject = "Confirmation";
$headers = "From: email@email.co.uk\r\n";
$headers .= "Reply-To: email@email.co.uk\r\n";
$headers .= "Return-Path: email@email.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body> ...lots of email coding in here...
</body>
</html>
';
if (mail($email,$subject,$message,$headers))
{
include 'thanks.html';
exit();
}
else
{
$error = 'Error sending.';
include 'error.html.php';
exit();
}
include 'registration.php';
?>
your database table has been incorrectly set up; it should be impossible to submit duplicate data.
Your code should rely on successful insertion of the data before sending an email.
Are you SURE it’s IE doing it? Or is it people hitting refresh because they get a blank screen? You will never reach the include statement at the bottom of this page.
Thanks for your reply, do you mean that I should only allow a field to be unique ie email addresses in the table therefore will reject if it is submitted again? Currently the only bit in the data that is different is the id which is auto increment, and the ticket number which gets updated with the id the rest is duplicate data.
I have captured stats from the site and only IE 11 and Edge 1 have the issue. I don’t think it’s likely that the issue is people pressing the form multiple times as the stats would show multiple visits. Also the time of the entires is exactly the same. The number of people (more than 20 so far) have this large amount of duplicate entries.
There are more than 150 entires which are fine, and have successfully reached the thank you page as well as received the confirmation email. I’m frankly baffled!! :0(
if (mail($email,$subject,$message,$headers)) //Let's assume we get here. Either this is true...
{
include 'thanks.html';
exit(); //And we stop processing here...
}
else //Or it's false...
{
$error = 'Error sending.';
include 'error.html.php';
exit(); //And we stop processing here...
}
//So we never get here, because both clauses of the if have invoked exit();
include 'registration.php';
And yeah, assuming that you’re storing information about a single event in which people will be attending or not, email should be unique, which will reject additional attempts to submit with that email.