I am working with a very simple form and trying to learn php. I have sessions working and post data working but I am trying to redirect the user to next page if the data is valid. I am running some validation which also I am successful with so far but only thing I am not finding is how to go to the next page if the data that they entered in the form is valid.If not it is already printing an error. I am very new to this so any help would be appreciated.
$nameErr = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["fname"])){
$nameErr = "name is required";
}
}
This is how my form looks like. I know I have to change something in the "action" part of the form as of right now it is printing to the same but not sure what. Can I write a if statement or something?
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="fname">FirstName:</label>
<input type="text" class="form-control" name="fname" id="fname" placeholder="Enter First Name">
<span class="error">* <?php echo $nameErr;?></span>