www.webdeveloper.com
Results 1 to 3 of 3

Thread: Php dropdwon menu

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    Php dropdwon menu

    <?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($mysqli, $_POST['sel_id']);
    echo $safe_id;
    }
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    731
    The default action of a form submission is GET, not POST. Add the action attribute to your form tag

  3. #3
    Join Date
    Nov 2013
    Posts
    2

    Thanks

    Quote Originally Posted by ginerjm View Post
    The default action of a form submission is GET, not POST. Add the action attribute to your form tag
    Thanks for your help but i want to do it through, the reason is i am learning so want to learn how to do it through post.

    I solved it i change the line
    <option value="<?php $x['id']?>" name="<?php $x['id']?>"><?php echo $x['display_name']?></option>
    TO
    <option value="<?php echo $x['id']?>" ><?php echo $x['display_name']?></option>

    means i add echo, to the value attribute, and deleted the name attribute,

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles