![]() |
coding search form question
I have a search form that when people type in the exact name of the user it shows results but if they don't add a space inbetween first and last names or they do and that is not the name it won't show results.
Such as John Doe shows results but not Johndoe Can I change this code below to show results for johndoe as well? Code:
if(isset($_POST['search'])) |
if you are pulling data from mysql then you should try search using phpmyadmin first this solves most issue. if you get required output then you can use specific query.
hope this helps., tizag[dot]com/mysqlTutorial/mysqlwhere.php |
Quote:
Code:
SELECT id, REPLACE(contactname, ' ', '') AS tmp FROM table WHERE tmp = '%' . $_POST['contactname'] . '%' |
Code:
// This assumes that mysql has already been hooked up at the time you construct this |
Quote:
|
Quote:
What I did will match names if they are like what was entered or if they are like what was entered with spaces removed, simple as that. No need to manipulate the database any further to get at what the OP requested. Quote:
I think ;p |
Quote:
Hope that answers your question. |
Quote:
For my part, I would never have it stored as a fullname like that anyway. I would have John in a first name field and Doe in a lsst name field. Everything in it's place. You can do lots of magic with code and a database but you still can't fix stupid, ya know ;p thnx |
Quote:
It looks like your search is probably vulnerable to SQL injections. Are you sanitizing the $_POST at all before this code even runs? If you aren't you could be in for a world of hurt, and you've just let the world know your page is vulnerable to injections. Check out this StackOverflow post for more on SQL injection attacks: stackoverflow dot com/questions/60174/best-way-to-prevent-sql-injection -st |
Quote:
|
All times are GMT -7. The time now is 12:04 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc