开发者

php MySQL LIKE search [duplicate]

开发者 https://www.devze.com 2023-04-02 11:01 出处:网络
This question already has answers here: Closed 11 开发者_StackOverflow中文版years ago. Possible Duplicate:
This question already has answers here: Closed 11 开发者_StackOverflow中文版years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消