Forum Moderators: coopster
I am also worried about sql injection. Any help would be appreciated.
What I have so far:
$search=trim($_POST["searchwords"]);
$keyword = split( " ", $search);
$er=0;
if (strlen($search)<2)
{$er=$er+1;
echo "<font size='-1' color='red'>Your last name must be longer than 1 letter. </font><br><br><br>";}
if ($er<1)
{
$sql="SELECT * from xtable WHERE";
foreach ($keyword as $key)
{if($keyword[0]==$key)
{$sql=$sql." xname LIKE '%$key%' OR yname LIKE '%$key%'";}}
$sql=$sql." ORDER BY xname";
$result = @mysql_query($sql,$connection) or die("Couldn't connect to database at this time...");
while ($row = mysql_fetch_array($result)) {
etc...
so ' would be '
I'm not sure what he did after that, but it came out neatly enough. I know it's not too helpful, but you might be able to extrapolate your own ideas from that.
$term= "O'Malley";
$term= preg_replace("/'/","''",$term); // produces O''Malley
This value can now be inserted/searched.
Select * from table where name like '$term';