dome90uk Posted July 11, 2007 Share Posted July 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/59416-solved-validation-problem/ Share on other sites More sharing options...
dome90uk Posted July 11, 2007 Author Share Posted July 11, 2007 ANSWERED ON ANOTHER FORUM Enclosed the For loop in this statement : if (!empty($searchterm)) { // your "for" loop } Quote Link to comment https://forums.phpfreaks.com/topic/59416-solved-validation-problem/#findComment-295449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.