php MySQL LIKE search [duplicate]
Possible Duplicate:
PHP MySQL multiple search query using option / select HTML form tags
I'm trying to make a basic search based on a drop down select option. I want to return a result based on the option selected. However, it doesn't seem to be working.
<?php
mysql_connect('localhost','root','');\
mysql_select_db('location');
?>
<center>
<form action="" method="post">
<select name="place">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<input type="submit" value="search" />
</form>
</center>
<?php
if(isset($_POST['place'])) {
$place = $_POST['place'];
if(!empty($place)) {
$query = "SELECT
description
FROM location
WHERE place LIKE '%$place%'
";
if($query_run = mysql_query($query)) {
if($result = mysql_fetch_assoc($query_run)) {
$description = $result['description'];
echo $description;
}
}
}
}
?>
UPDATE: never mind got it.
Enable error reporting to see what mistake you made. Then use:
$result= mysql_fetch_array($query_run);
echo $result['description'];
And, which could be said for about every php + mysql question: read about SQL Injection.
精彩评论