Sofia M
Sofia M

Reputation: 11

How to fill HTML form fields from SQL server with PHP

I am trying to get data and dump them to my HTML form from the SQL server. For example I type a name to my HTML form and I want to dump all the information of that name from the database ( last name, email etc.).

I created the form and a simple PHP connector that finds the name and the other information for that name ( last name). I can echo it on PHP file but I want to show it on the input last name as a value so I can use it for JavaScript purpose.

<form class="form-inline">

  <table class="table table-condensed">
    <tbody>
      <tr>


        <td><label for="lastname">Last Name:</label> </td>
        <td><input type="name" class="form-control" id="lastname" placeholder="last name"></td>
        <td><label for="firstname">First Name:</label> </td>
        <td><input type="name" class="form-control" id="name" placeholder="first name"></td>


      </tr>

    </tbody>
  </table>
</form>

Upvotes: 0

Views: 1247

Answers (2)

Craig Crane
Craig Crane

Reputation: 1

this is how I got this to work

<input type="text" name="first_name" value="' . $row["POLCustName"] . '">

There was a <?php to start and an echo to do the Form within the PHP. But for the value of the SQL row to process, you needed the quotes and then a single quote to allow the PHP to work, otherwise you just got the statement above. Also, it required the period before and after as shown. Anyway, this worked for me.

Upvotes: 0

waterloomatt
waterloomatt

Reputation: 3742

Add it as the value for the HTML input.

<form ...>
    ...
    <input type="text" name="last_name" value="<?php echo $row->last_name; ?>">
    ...
</form>

Upvotes: 1

Related Questions