OK, I have this great script which works great. The script takes the user supplied first name and id number and uses it to find a match in the .csv file. If a match is found, user is forwarded to a specific URL. Thanks to Martyr2 for the awesome help with this one.
What I have run into is that in the .csv file there are duplicates, and sometimes three or more. So the script is finding 2, 3, and sometimes 4 matches. The problem is it will not forward the user until ALL matches are found. So a name/id combination that shows up 4 times in the .csv will force the user to enter his/her name/id in the form 4 times! Strange huh? Any way around this little anomaly in the code? I've been told the .csv cannot strip duplicates because of the type of program that creates it. Thanks for any ideas!
CODE
<form name="input" method="post"
action="<?php echo $_SERVER['php_test/SCRIPT_NAME']?>">
<p><label for="firstname">First Name: </label>
<input type="text" name="fname" id="fname" /></p>
<p><label for="idnumber">ID Number: </label>
<input type="text" name="idnumber" id="idnumber" /></p>
<p><input type="reset" name="reset" value="reset" />
<input type="submit" name="submit" value="submit" /></p>
</form>
<?php
if (isset($_POST['submit'])) {
$fname = $_POST['fname'];
$idnum = $_POST['idnumber'];
$array = file("test.csv");
$match_found = false;
foreach ($array as $line) {
$pieces = explode(",",$line);
if ((trim($pieces[0]) == $fname) && (trim($pieces[2]) == $idnum)) {
$match_found = true; break;
}
}
if($match_found){
echo 'You are signed in!';
$URL="desired URL";
header ("Location: $URL");
} else {
echo 'nope';
}
}
?>