Reputation: 17
The following code is for the form for the user to enter numbers into.
<input type="number" name="team1" class="inputbox" oninput="validity.valid||(value='')" min="0"> <input type="number" name="team2" class="inputbox" oninput="validity.valid||(value='')" min="0">
<input type="number" name="team3" class="inputbox" oninput="validity.valid||(value='')" min="0"> <input type="number" name="team4" class="inputbox" oninput="validity.valid||(value='')" min="0">
<input type="number" name="team5" class="inputbox" oninput="validity.valid||(value='')" min="0"> <input type="number" name="team6" class="inputbox" oninput="validity.valid||(value='')" min="0">
<input type="number" name="team7" class="inputbox" oninput="validity.valid||(value='')" min="0"> <input type="number" name="team8" class="inputbox" oninput="validity.valid||(value='')" min="0">
These numbers are sent to roundThree.php, which compares number 1 and number 2, number 3 and number 4, and so on. It figures out which is higher than the other.
$teams = Array($team1, $team2, $team3, $team4, $team5, $team6, $team7, $team8, $team9, $team10, $team11, $team12, $team13, $team14, $team15, $team16);
$winCheck = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for ($x=0; $x < count($teams); $x+=2) {
if ($teams[$x] > $teams[$x + 1]) {
winCheck[$x] = 1;
}
elseif ($teams[$x] < $teams[$x + 1]) {
$winCheck[$x + 1] = 1
}
else {
}
};
I want to use input validation to prevent users from entering two numbers that are equal to each other. Is there some kind of validation I can put in else{} to either send the user back to the page and make them re-enter two different numbers?
Upvotes: 0
Views: 69
Reputation: 22
using array_unique() allows you to return an array without duplicate values. Then compare your new unique array with your original array.
Example:
if (array_unique($teams) == $teams) {
// Array is unique
} else {
header('Location: example.url'); // Bring back to desired page
}
Upvotes: 1