I am trying to set up a script to search a flat file for a specific address match. If the address is already there, I want the script to exit. If it isn't, I want it to write the new info to the file. I can get it to write to the file okay but cannot seem to master the checking the flat file for a match and exiting if found. What am I missing here?
The values for form variables $name, $address, and $city come from the form being submitted. They are passing correctly via post method. This is the most recent code I've been trying:
<?
//line to look for
$search = "$address";
$file = file("test.txt");
$key = array_search($search,$file);
if($key === TRUE)
{
echo "You have already submitted your information";
exit;
}
else
{
//write new info to file
$fp = fopen("test.txt", "a");
fwrite($fp,stripslashes("$name;"));
fwrite($fp,stripslashes("$address;"));
fwrite($fp,stripslashes("$city;"));
fclose($fp);
}
?>