0
<?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;
}
?>
4
Contributors
4
Replies
26
Views
3 Years
Discussion Span
Last Post by diafol
0

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

0

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

1

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">

Edited by Bachu: text correction

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.