bigkev1983 Posted September 23, 2006 Share Posted September 23, 2006 Hello thereI'm pretty new to PHP and mianly use Dreamweaver to come up with most of the code for search interfaces to be honest so I'm hoping you guys can help me.I have this select statement for my search results page:$query_directory = sprintf("SELECT * FROM directory WHERE Name LIKE '%".$_POST['name']."%' ORDER BY id DESC", $colname_directory);to get all records from the database whose name contains characters typed in by the user from the search form. However, it doesn't work and SQL just comes back with an error. The standard statement (below) DOES return results but obviously it doesn't do what I need it to as it forces the user to type in the whole name exactly:$query_directory = sprintf("SELECT * FROM directory WHERE Name = '".$_POST['name']."' ORDER BY id DESC", $colname_directory);Can anyone help me make the first statement work?Kev Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted September 23, 2006 Share Posted September 23, 2006 sometimes I'll replace the spaces with percents...$query_directory = sprintf("SELECT * FROM directory WHERE Name = '".str_replace(" ","%",$_POST['name'])."' ORDER BY id DESC", $colname_directory); Quote Link to comment Share on other sites More sharing options...
bigkev1983 Posted September 23, 2006 Author Share Posted September 23, 2006 Thanks for replying.When I tried this, I didn't get an error message this time but unfortunately I don't get any results either. Quote Link to comment 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.