Here is a piece of code in process.php file:
if(isset($_POST['skip'])) {
session_destroy();
header('Location: main.php');
} else {
if(!empty($_SESSION['nameErr']) || !empty($_SESSION['quoteErr'])) {
header('Location: index.php');
} else {
if(mysqli_query($connection, $query)) {
// echo 'new record';
session_destroy();
header('Location: main.php');
} else{
// echo "Error: " . $query . "<br>" . mysqli_error($connection);
header('Location: index.php');
}
}
}
I have a form with two 'submit' buttons in index.php file:
<form action="process.php" method="post">
<span class="error"> <?php if (isset($_SESSION['nameErr']))
{echo $_SESSION['nameErr'];}?> </span> <br>
<label> Your name: <span>*</span>
<input type="text" name="name"> </label><br/>
<span class="error"> <?php if (isset($_SESSION['quoteErr']))
{echo $_SESSION['quoteErr'];}?> </span> <br>
<label> Your quote: <span>*</span>
<textarea rows="5" cols="50" name="quote"></textarea></label><br/>
<input type="submit" value="Add my quote!"name="add">
<input type="submit" value="Skip to quotes!" name="skip">
</form>
If the 'skip' button is clicked, then redirect to 'main.php' page. The above code in process.php works, but if I changed a little bit:
if(isset($_POST['skip'])) {
session_destroy();
header('Location: main.php');
}
if(!empty($_SESSION['nameErr']) || !empty($_SESSION['quoteErr'])) {
header('Location: index.php');
} else {
if(mysqli_query($connection, $query)) {
// echo 'new record';
session_destroy();
header('Location: main.php');
} else{
// echo "Error: " . $query . "<br>" . mysqli_error($connection);
header('Location: index.php');
}
}
When click the 'skip' button, it still stays in the index page. I'm wonder if that because header() is an asynchronous function in PHP? I couldn't find any official reference to it. Please provide some tips. Thanks in advance.