Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Search Feature Problem


PHP Search Feature Problem

Reply
  #1 (permalink)  
Old 08-13-09, 04:24 AM
jilawatan jilawatan is offline
New Member
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb PHP Search Feature Problem

Hello Guys,

I am just a beginner in PHP. I am learning PHP from tutorials. I just tried to make a simple PHP search feature and connect it to my database to search the keywords from my database table. The tutorial is according to the PHP Version 4. But, my hosting server consist of PHP version 5. I think thats why it is not working. When I am trying to submit the keyword to search through an html form. It is showing me all the keywords from the table. But, it should match up with only that keyword, which i am entering in the html form. It is showing me all the records from database table.
Kindly, help me out in this. Here is my PHP and HTML code.

HTML CODE:

PHP Code:

<form action="result.php" method="POST">


<
input type="text" name="name"><BR><BR>

<
input type="submit" value="Search">

</
form
PHP CODE:




PHP Code:

<?


if (!$name) {

echo 
"No Search Result";
exit;
}


$db mysql_connect("localhost""sqlusername""sqlpassword");
mysql_select_db("sqldatabase"$db);

$query "SELECT people.name, people.Height, people.Date
FROM people WHERE name LIKE '%"
.$name."%'";

$result mysql_query($query);

while (
$record mysql_fetch_assoc($result)) {

while ( list(
$fieldname$fieldvalue) = each($record)) {


echo 
$fieldname ": <b>" $fieldvalue "</b><br>";

}
echo 
"<br>";

}

?>

I will appreciate the help from you guys.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-13-09, 04:45 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
$query = "SELECT people.name, people.Height, people.Date
FROM people WHERE name LIKE '"
.$name."'";

The "%" symbols make the search less strict, so you get more irrelevant results.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-13-09, 09:21 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Sanitize your data- never, ever pass variables into your database without screening them.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced Search Problem php-learner PHP 1 10-13-05 10:51 AM
Search database with multiple AND problem Bonzo PHP 8 07-14-05 03:09 PM
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 12:19 PM


All times are GMT -5. The time now is 01:02 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.