Note: Without using jquery or javascript validate
How to validate with multiple input with same name?
<form action="" method="post"">
Product1 <input type="text" name="your_product[]"> <br>
Product2 <input type="text" name="your_product[]"> <br>
.....
Product N <input type="text" name="your_product[]">
<input type="submit"
</form>
PHP
if($_POST)
{
$error = "";
for($i=0; $i < count($_POST['your_product']); $i++)
{
if($_POST['your_product'][$i] == "")
{
$error = "Please fill your product";
}
else
{
$_SESSION['product'][$i] = $_POST['your_product'][$i];
}
}
}
Problem: If user fill the first input(but not fill the second input), the first value still contain to session. I want to stop the process for first contain session if he forgot fill in the next input. How could I do?
breakto exit the for loop on the first error