PHP help please

Soldato
Joined
19 Jul 2006
Posts
2,960
Location
Leicester
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.

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/>";
}

}

}

}
 
Soldato
OP
Joined
19 Jul 2006
Posts
2,960
Location
Leicester
Thanks for the reply.

There might be more than one user returned though if they have the same surname as another, so I'm still not sure how to do it.

Thanks in advance for any help.
 
Soldato
OP
Joined
19 Jul 2006
Posts
2,960
Location
Leicester
Thanks for the help.

Markeh, it works great, thanks...although I had to spend a few minutes thinking 'why doesn't it work?' then I saw no ; at the end!
 
Back
Top Bottom