![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
|
New Webmasters ask "How-To" questions here. This is where other fucking Webmasters help. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Jul 2006
Location: Toronto Canada
Posts: 563
|
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'])) { $searchs = array(); if(!empty($_POST['contactname'])) { $searchs[]="contactname LIKE '%".$_POST['contactname']."%'"; } |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Nov 2012
Posts: 732
|
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
__________________
![]() Ex GF Films | Grab Dollars Up To 80% Rev-Share | 255 Day Cookie | Legal Content | Variety of Promo Tools | CCBill Program | GF Niche james[at]grabdollars[dot]com | ICQ::611-99-zero-zero-20 |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#3 | |
Confirmed User
Industry Role:
Join Date: Nov 2012
Location: New Orleans
Posts: 213
|
Quote:
Code:
SELECT id, REPLACE(contactname, ' ', '') AS tmp FROM table WHERE tmp = '%' . $_POST['contactname'] . '%'
__________________
Tent Pitcher - Adult Search Engine |
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#4 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
Code:
// This assumes that mysql has already been hooked up at the time you construct this if(isset($_POST['search'])) { $searchs = array(); if(!empty($_POST['contactname'])) { // first for protection against sql injection $contact2use='%' . mysql_real_escape_string($_POST['contactname']) . '%'; // then make a second version to search for $compressedcontact=str_replace(' ','',$contact2use); // then look for either version $searchs[]="contactname LIKE '" . $contact2use . "' or contactname like '" . $compressedcontact . "'"; } |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#5 | |
Confirmed User
Industry Role:
Join Date: Nov 2012
Location: New Orleans
Posts: 213
|
Quote:
__________________
Tent Pitcher - Adult Search Engine |
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#6 | ||
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
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
__________________
All cookies cleared! |
||
![]() |
![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Industry Role:
Join Date: Nov 2012
Location: New Orleans
Posts: 213
|
Quote:
Hope that answers your question.
__________________
Tent Pitcher - Adult Search Engine |
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#8 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,053
|
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
__________________
All cookies cleared! |
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#9 | |
Registered User
Industry Role:
Join Date: Oct 2012
Posts: 53
|
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 |
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Industry Role:
Join Date: Nov 2012
Location: New Orleans
Posts: 213
|
Quote:
__________________
Tent Pitcher - Adult Search Engine |
|
![]() |
![]() ![]() ![]() ![]() |