TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-06-2008, 09:37 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default [SOS]a search for a database ,double click here

hi ,
well im trying to do a search form for my database here is the code =>
PHP Code:
<?php

if(!empty($_POST['search']) ) {
$con mysql_connect("localhost","root","") ;
$db mysql_select_db("test") ;
$sql "select * from webt where name='%$_POST[search]%' ";
$res mysql_query($sql) ;
if (
mysql_num_rows($res) == ) {
          echo 
"No result";
 }else{ while (
$row mysql_fetch_array($res) ) {
       
      echo 
$row[name]."<br><br>" 
       }
       
}
}else{ echo
"full the form"; } 

?>
<form method="post" action="search.php" >
<b>Search</b><input type="text" name="search" >
<input type="submit" value="Search" >
</form>
and in the database there is name='aa'
name is the name of the column
anyway when i delete "%" the code works great but when i add them it douesnt work
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-06-2008, 09:46 PM   #2 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

% is a wildcard, that should only be used for LIKE mysql searches...

PHP Code:
$db mysql_select_db("test") ;
$sql "select * from webt where name='%$_POST[search]%' ";
$res mysql_query($sql) ; 
Should probably be:
PHP Code:
$db mysql_select_db("test") ;
$sql "select * from webt where name LIKE '%$_POST[search]%' ";
$res mysql_query($sql) ; 
please note, your script is FAR from secure and you should look at some topics here regarding:
SQL injections protection
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
The Following User Says Thank You to bluesaga For This Useful Post:
webtuto (01-06-2008)
Old 01-06-2008, 09:47 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

The actual syntax for that is like so:

sql Code:
SELECT
    myColumn
FROM
    myTable
WHERE
    myColumn
LIKE
    '%findThis%'

Edit: Meh young William, meh. Nothing else to add.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
webtuto (01-06-2008)
Old 01-06-2008, 10:07 PM   #4 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

thanks it works but for exemple you search "aaa" , i want it to give me the result from database as "aa"
but it douesnt :o
it give "no result"
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-12-2008, 01:15 PM   #5 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

@webtuto

the % procent means that it replaces "anything" so for example you want to find a name ending with "Harrison" and you would search for "%Harrison". See the % in the beginning ?

Switch place of the % if you want to search for the name beginning with "Harrsion" as so "Harrison%". Catching on now ?

And if you want to search for a name containing "Harrison" then it would be "%Harrison%".

I belive you can use a ? questionmark for replacing a single char.
Correct me if im out on a limb here ?

And see Wildhoney and bluesaga´s post above.

I had trouble with the LIKE thing in my early days of MySQL queries to.

Good Luck.

/EyeDentify
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:07 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design