<?php
//connecting to the database and running query

$dbc=mysqli_connect('localhost','root','','sam_telephone');
$get_list_sql="SELECT id, CONCAT_WS(',', l_name, f_name) AS display_name FROM 
    master_name;";
$get_list_res=  mysqli_query($dbc, $get_list_sql);
?>

<!--Building of drop down menu start from here-->

<form action="post.php" method="post">
    <select name="sel_id">
       <option value="">--Select One--</option> 
<!--Starting while loop for fetching the array-->
<?php 
while($x=mysqli_fetch_array($get_list_res,MYSQLI_BOTH)){
?>
<option value="<?php $x['id']?>" name="<?php $x['id']?>"><?php echo $x['display_name']?></option>
<?php
}
?>
</select>
    <input type="submit" value="submit"/>
    </form>
<!--Till here every thing work fine-->


<?php

// this portion is not working what i want to do its to get the id, because if 
//I can get the id, i can run the query and get the result which i want to get
// from this table
if(isset($_POST['sel_id'])){
    $safe_id = mysqli_real_escape_string($dbc, $_POST['sel_id']);

    echo $safe_id;
}
?>

Recommended Answers

All 4 Replies

it's like telephone directory, in drop down menu, its show the people who are in the data table.
what i want to do is to select the people from drop down menu and when i click on the submit button, it should show me the result for that particular person

nothing is wrong with your method, try using different browser.
I've checked you way and its working fine.

Hai;

You are forgotten to echo the option value.

Please change this

<option value="<?php $x['id']?>" name="<?php $x['id']?>"><?php echo $x['display_name']?></option>

into

<option value="<?php echo $x['id']?>" name="<?php echo $x['id']?>"><?php echo $x['display_name']?></option>

If you want to print this result on same page..
please chage this

<form action="post.php" method="post">

into

<form action="" method="post">
Member Avatar for diafol

I strongly suggest a separation of php code and html markup where possible.

The majority of the php code can be placed above the doctype declaration or even in an include file, even wrapped up in a generic dropdown-producing function.

BTW, I would suggest using GET not POST. You don't seem to be modifying anything.

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.