-3

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.

1
  • 1
    This is not how mysql_query() works. Refer to the manual for examples. Also turn on error reporting - there will be error messages in the code you show Commented Sep 6, 2011 at 7:57

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.