Jump to content

[SOLVED] Validation Problem


dome90uk

Recommended Posts

Hi,

 

I have inherited a piece of code from a client which I cannot get to work properly. The validation in the script doesn’t work – ( i.e. when a user doesn’t put anything into the search box they receive losts of this error.

 

“Warning: stristr() [function.stristr]: Empty delimiter. in /home/ public_html/newsite/export.php on line 19”

 

Here is the code for the Function:

<?
$searchterm=$_GET[search];
$fname="export.csv";
$numfields=7;
$fd = fopen ($fname, "r");
$contents = fread ($fd, filesize ($fname));
$contents=trim($contents);
echo "<br><br>";
$contents=strtr($contents,chr(10),",");
fclose ($fd);
$fvalues=explode(",",$contents);
$numbers=count($fvalues);
$found=0;

	for ($i=0;$i<=$numbers;$i=$i+$numfields)
	{
		$a1=$fvalues[$i+2];
		if (stristr($a1,$searchterm))
		{
		$company=trim($fvalues[$i]);
		echo "<p><b>$company</b><br>";
		$a1=$fvalues[$i+1];
		echo "Contact: $a1<br>";
		$a1=$fvalues[$i+2];
		echo "Address: $a1<br>";
		$a1=$fvalues[$i+3];
		echo "Telephone: $a1<br>";
		$a1=$fvalues[$i+4];
		echo "Fax: $a1<br>";
		$a1=$fvalues[$i+5];
		echo "Email: <A HREF='mailto:$a1'>$a1</A><br>";
		$a1=$fvalues[$i+6];
//			echo "Website: $a1</A><br>";
		if ($a1=="None")
		{
			$a1="";
		}
		echo "Website: <A HREF='http://$a1' TARGET='_blank'>$a1</A><br>";
		$found=$found+1;
		echo"<br></p><hr>";
		}

	}
	if ($found>0)
	{
		echo "<p><br>$found member(s) found.<br></p>";
	}
	else
	{
		echo "<p><br>Sorry, no members found in that area.<br></p>";
	}
		?>

 

The code searches a CSV file for members contact details and displays them on the webpage.

 

I have a very little knowledge of PHP and would really appreciate any guidance or help that you could share. Thanks.

 

Dome

 

 

Link to comment
https://forums.phpfreaks.com/topic/59416-solved-validation-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.