ChrisRChamberlain
Programmer
Hi all
Following thread434-1352591, the $searchstring variable, derived from $searchstring =$_POST['searchstring']; needs to be checked for the existence of either square bracket and an appropriate error message printed.
The following code checks for the existence of the left bracket as opposed to both, (needs an 'OR' or equivalent?), and does not have an 'else' which could be used for an error message.
At the moment it appears that only the inclusion of the brackets causes an error message.
TIA
![[pc2] [pc2] [pc2]](/data/assets/smilies/pc2.gif)
PDFcommander.com
motrac.co.uk
Following thread434-1352591, the $searchstring variable, derived from $searchstring =$_POST['searchstring']; needs to be checked for the existence of either square bracket and an appropriate error message printed.
The following code checks for the existence of the left bracket as opposed to both, (needs an 'OR' or equivalent?), and does not have an 'else' which could be used for an error message.
Code:
<?php
//connect to the database
$connectionstring = odbc_connect("vfptable", "", "");
// searchstring passed from form
$searchstring = $_POST['searchstring'];
$lbracket = "[";
$rbracket = "]";
if(stristr($searchstring,$lbracket)===FALSE){
$searchstring = strtolower($searchstring);
$searchstring = "[" . $searchstring . "]";
// Get number of records
$countQuery = "SELECT COUNT(*) FROM pagedata ".
"where $searchstring $ innertext";
$result = odbc_exec($connectionstring, $countQuery);
odbc_fetch_row($result,0);
$numRecords = odbc_result($result, 1);
// Execute search query
$Query = "SELECT * FROM pagedata ".
"where $searchstring $ innertext";
$queryexe = odbc_do($connectionstring, $Query);
// Query database
print ("<div id='feature'>");
print ("Total instances found is ".$numRecords);
print ("<br>");
print ("<br>");
$instances=0;
while(odbc_fetch_row($queryexe))
{
$filename = odbc_result($queryexe, 1);
$title = odbc_result($queryexe, 2);
$dispstring = odbc_result($queryexe, 4);
print ("$instances"+1);
print (".");
print (" ");
print ("<a href='$filename'>$title</a>");
print ("<br>");
print ("$dispstring");
print ("<br>");
print ("<br>");
$instances=$instances+1;
}
print ("</div>");
}
//disconnect from database
odbc_close($connectionstring);
?>
TIA
FAQ184-2483 - answering getting answered.
Chris ![[pc2] [pc2] [pc2]](/data/assets/smilies/pc2.gif)
PDFcommander.com
motrac.co.uk