Hi,
I have a script that searches a .txt file based on a surname the user inputs.
My problem is, I can't seem to add an error message if no users are found.
I did manage to get an error message to display, but it was displaying for the amount of people found in the txt file, but that didn't match the search, along with the one user found.
I've not done PHP for a few years now and can't seem to figure this out.
I did originally find this script on the Internet and have changed it a little bit.
Thanks for any help.
I have a script that searches a .txt file based on a surname the user inputs.
My problem is, I can't seem to add an error message if no users are found.
I did manage to get an error message to display, but it was displaying for the amount of people found in the txt file, but that didn't match the search, along with the one user found.
I've not done PHP for a few years now and can't seem to figure this out.
I did originally find this script on the Internet and have changed it a little bit.
Thanks for any help.
PHP:
if ( isset( $_POST['search'] ) )
{
$q = $_POST["surname"];
if (empty($q))
{
echo "You must enter a Surname in the box below.";
}
else
{
$f = fopen("list.txt", "r");
while (($line = fgets($f)) !== FALSE)
{
if (strstr($line, $q)) {
print "<li>$line<br/>";
}
}
}
}