I am using the PHP below with a form that I am using to determine whether a user has authorized access to the next page.
However, I have to fill out the form at least twice for the information to go through. If I enter in the correct information on the first attempt, it will say give the appropriate error statement I coded in, then if I put literally anything into the form and hit submit, it will go through.
I can put incorrect information a million times and it won't go through, but if I put the correct info once, I have to hit submit then fill out the form again with any information and hit submit for a second time, then I will be taken to the next page. I removed the if (isset ($_COOKIE)
block completely to see if it made a difference, but it did the exact same thing.
<?php
include_once "database.php";
session_start();
if (isset($_POST['submit'])) {
if (isset($_COOKIE['first'])){
setcookie("first",'',time()-3600,"/");
setcookie("last",'',time()-3600,"/");
setcookie("city",'',time()-3600,"/");
}
$first=$_POST["first"];
$last=$_POST["last"];
$city=$_POST["city"];
setcookie("first",$_POST["first"],0,"/");//cookie expires after browser closes
setcookie("last",$_POST["last"],0,"/");//cookie expires after browser closes
setcookie("city",$_POST["city"],0,"/");//cookie expires after browser closes
clearstatcache();
$sql="SELECT * FROM invited WHERE FIRSTNAME='".$_COOKIE['first']."' AND LASTNAME='".$_COOKIE['last']."' AND CITY='".$_COOKIE['city']."'";
$found=mysqli_query($conn,$sql);
echo "$first
$last
$city";
if (mysqli_num_rows($found)){
$success="<script>window.location.href='rsvp.php'</script>";
}
else{
$fail="ERROR, Could not find";
}
}
?>
HTML Form:
<form action="" method="POST">
<p>Enter Family Name (as it appears on your invitation): </p>
<input class="entry" type="text" name="first" placeholder="FIRST NAME" required><br><br>
<input class="entry" type="text" name="last" placeholder="LAST NAME" required><br><br>
<input class="entry" type="text" name="city" placeholder="CITY (ONLY)" required><br><br>
<input type="submit" onclick="getCookie()" name="submit">
</form>