Fecting records from the database using the value in a selection box

301
April 25, 2017, at 11:01 AM

Please, help me out to solve the following problem. I have a web page that takes some information from the user. I have loaded all the Member IDs to a select box, which a member can select their own Member ID easily. My problem is, I want to display automatically the first name and the Last name of the that particular user once his/her Member ID is selected. I know that I require Javascript or Jquery with PHP and MySql, But I don't know how to use it properly. Part of the coding is as follows.

//loads Member ID to a select box

<?php
include('connectdb.php');
$sqlselect = "SELECT MemID FROM Member" ;
$result = mysqli_query($dbcon,$sqlselect);
<?

//displaying membr ID in select box

<html><head><title></title></head>
<body>
<form action="bookrequestmem.php" method="post"> 
<label for="memberid">Member ID:</label><br>
<select id="memid" name="memid1">  
            <option>Select Member ID</option>";
            <?php while($row = mysqli_fetch_array($result)):;?>
            <option><?php echo $row[0];?></option>";
            <?php endwhile;?>
 </select>
 <label for="fname">First Name:</label><br>
 <Input type="text" name="memfname"/>
 <label for="lname">Last Name:</label><br>
 <Input type="text" name="memlname"/>
 </form>
 </body>
 </html>

Please tell me how to disply the First name and the Last name automatically when the proper Member ID is selected.

Answer 1
    $(document).ready(function(){
            $("#memid").change(function(){
                var id = $("#memid").val();
                 $.ajax({
                            type: 'POST',
                            url: 'getname.php',
                            data: {id: id},
                            success: function (data) {
                                var name = data.split(" ");
                    $("#fname").val(name[0]);
                    $("#lname").val(name[1]);   
                            }
            });
 });
        });

Then in getname.php file use id posted by the ajax method and fetch the firstname and lastname of the member and echo them separated by space as we are using split on "space" and then set the values of the input fields.

Rent Charter Buses Company
READ ALSO
Containing a grid of cells that keep their aspect ratio

Containing a grid of cells that keep their aspect ratio

I'm looking for a modern, simple CSS way to contain a grid of cells that maintain their aspect ratio yet will grow to 'fill' their container as best as possibleI'd like to stress the word 'contain': I want both the grid's width AND height to fit in the container

296
using multiple php pages in html form validation

using multiple php pages in html form validation

I am brand new to PHP, and I am attempting to recreate a PDF in the shape of a PHP page

355
Making an api request data into a url

Making an api request data into a url

Im making an api call and receiving the data, Im trying to make the url and content load to my blog using an http request, to avoid having to rewrite my workHere is an example of what im trying to accomplish

363
Force Aurelia to call lifecycle methods of new route with same component but different route parameters

Force Aurelia to call lifecycle methods of new route with same component but different route parameters

I have a parent page with a router, that is set up with only 2 routes:

309