<form action="searchdetail.php" method="post"> 
    <select name="searchby">
    <option value="gname">Guest Name</option>
    <option value="city">Guest City</option>
    <input name="query" type="text" />
    <input name="subval" type="submit" value="Search" />

and searchdetail.php

            $query = mysql_real_escape_string(trim($_POST['query']));   
            $sql = mysql_query ("SELECT * FROM voucher WHERE gname = '$query'"); 
            echo "<table border=1 width=860 align=center cellsapcing=5 cellpadding=5>";
            echo "<tr>";
            echo "<th>Guest Name</th>";
            echo "<th>Guest City</th>";
            echo "</tr>";
        while ($row = mysql_fetch_array($sql)) 
                echo "<tr>";
                echo "<td>" . $row['gname'] . "</td>";
                echo "<td>" . $row['city'] . "</td>";
                echo "</tr>";

how can i get combobox value from that page. for example if user selects GUEST CITY from combobox and then he types PORT BLAIR in the input text field. then searchdetail.php page should show the PORT BLAIR guests. how can i do that? i'm little bit confused.. before i have done this but i'm using only textbox. But here i want to pass the id of combobox value too.. any help...

Recommended Answers

All 4 Replies

Member Avatar
$query = mysql_real_escape_string(trim($_POST['query']));   
$field = mysql_real_escape_string(trim($_POST['searchby']));
$sql = mysql_query ("SELECT * FROM voucher WHERE `$searchby` = '$query'");

I'm assuming that your DB fields are the same as the values in the select option values. Consider moving away from mysql - I'm sure I've mentioned this before.

i tried. but still its not working. here that combobox values are my table column names. first i want to select my table column name (what user select in that combobox) then i want to get row values(what user types in that text field) from that particular column name.???

Member Avatar

Have you echoed out the query string to see what it gives?

$str = "SELECT * FROM voucher WHERE `$searchby` = '$query'";
echo $str;
$sql = mysql_query ($str) or die(mysql_error());

That's always a good idea...

now i got it thanks...
i think this is the problem

$sql = mysql_query ("SELECT * FROM voucher WHERE `$searchby` = '$query'");

now i changed :

$sql = mysql_query ("SELECT * FROM voucher WHERE `$field` = '$query'");

so only i didn't get the results. now its ok...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.