Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:28+00:00 2026-06-14T20:28:28+00:00

I have a HTML form which has 3 text input fields: id , name

  • 0

I have a HTML form which has 3 text input fields: id, name, and contact. My DB table has same named columns and the values are id=1, name=mark & contact=1234. Now, if I enter ‘1’ in my html form’s id field & press enter then how can the rest of the form’s field (like: name, contact) will be automatically filled?

What I’ve done so far is:

my index.html file(I think its wrong because I didn’t use JSON before):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type = javascript>

$("#email").bind("change", function(e){
  $.getJSON("lookup.php?email=" + $("#email").val(),
        function(data){
          $.each(data, function(i,item){
            if (item.field == "first_name") {
              $("#first_name").val(item.value);
            } else if (item.field == "last_name") {
              $("#last_name").val(item.value);
            }
          });
        });
});


</script>>
</head>

<body>
<form>
<input  type="text" name="email" id="email" />
<input type="text" name="first_name" id="first_name" />
<input type="text" name="last_name" id="last_name" />

</form>
</body>
</html>

my lookup.php file:

<?php
//look up the record based on email and get the firstname and lastname
$email=$_GET['$email'];

$con = mysql_connect("localhost", "root", "");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("json", $con); //DB name= json

 mysql_select_db("json"); //DB name= json

  $result = mysql_query("SELECT * FROM json1 
     WHERE email LIKE '$email%'");      //DB table name=json1
if (mysql_num_rows($result) == 1) {
        while ($myrow = mysql_fetch_array($result)) {
//build the JSON array for return
$json = array(array('field' => 'first_name', 
                    'value' => $firstName), 
              array('field' => 'last_name', 
                    'value' => $last_name));
echo json_encode($json );
        }
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:28:29+00:00Added an answer on June 14, 2026 at 8:28 pm

    To fill the form without reloading the page you will have to use Ajax to request the data from the server (database) and then fill it using javascript, i suggest reading about ajax functions with jquery.

    if you want for example to fill the id and click a button and the page will reload with the data, use the php post method, a quick example:

    <?php
        if($_POST['getdata']){
            $id = $_POST['itemID'];
            /*
            connect to the database and get the data here and return in with an array called $data for example
            */
        }
        if($_POST['savedata']){
            /*
            use this if you want to do another action to the form, update the values for example
            */
        }
    ?>
    <form action='' method='POST'>
        <input name="id" value="<?php echo $data['id'];?>" type="text" />
        <input name="name" value="<?php echo $data['name'];?>" type="text" />
        <input name="contact" value="<?php echo $data['contact'];?>" type="text" />
        <input name="getdata" value="Get Data" type="submit" />
        <input name="savedata" value="Save Data" type="submit" />
    </form>
    

    UPDATE:

    regarding your update

    first of all you better use PDO or MySQLi database instead of MySQL function because mysql_* is no longer maintained so since you are fresh to php learn PDO instead.

    to your code, if you are expecting a single row from the database select statement, you should not use while() because its used to loop through the mysql object which has more than one row.

    if we assume your table has exactly email, firstname, lastname fetch it directly into an array:

    $myrow = mysql_fetch_assoc($result);
    

    then convert that array into json and print it out

    echo json_encode($myrow);
    exit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML form that has certain fields which i am opening inside
I have a form which has multiple input fields, and 3 main options. depending
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
I have a webrequest that returns a html response which has form inside with
I have a html page with a form. The form has Div which gets
I have an HTML Contact us form which I plant on my client's HTML
I have HTML form with lots of select and input fields, using it a
I have a text input which has a default value password. When the user
Hi just looking for some direction, I have a HTML form which has several
I have an HTML document with the following form: <form> <input type=text id=price> <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.