Beginner Question - How to populate HTML form from PHP/MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    Beginner Question - How to populate HTML form from PHP/MySQL

    I have found many examples of how to access an HTML text field from
    PHP, but cannot find the reverse - how to load an HTML form from a
    MySQL database.

    Specifically, I have an HTML form which contains several text boxes
    that correspond to the fields in a MySQL file. What I want to do is
    call a PHP form that reads one record from MySQL and then populates
    all of the HTML fields on the calling form.

    The call to MySQL is not a problem - that works and I can use "Echo"
    to verify that I have successfully read a record. Now, how do I get
    that data back into the original HTML form?

    Thanks!!
    Mark Jones
  • Marcin Dobrucki

    #2
    Re: Beginner Question - How to populate HTML form from PHP/MySQL

    Mark wrote:
    [color=blue]
    > The call to MySQL is not a problem - that works and I can use "Echo"
    > to verify that I have successfully read a record. Now, how do I get
    > that data back into the original HTML form?[/color]

    Assuming you have something that came from the db stored in a
    variable, then it's a simple case of telling html that there is a value
    to be used, eg for text and textarea:

    $foo = "something from db"
    $bar = "something very long from db"

    ....
    <input type="text" name="short" value="$foo">
    <textarea name="long">$ba r</textarea>
    ....

    /Marcin

    Comment

    • FLEB

      #3
      Re: Beginner Question - How to populate HTML form from PHP/MySQL

      Regarding this well-known quote, often attributed to Marcin Dobrucki's
      famous "Wed, 03 Dec 2003 16:39:43 GMT" speech:
      [color=blue]
      > Mark wrote:
      >[color=green]
      >> The call to MySQL is not a problem - that works and I can use "Echo"
      >> to verify that I have successfully read a record. Now, how do I get
      >> that data back into the original HTML form?[/color]
      >
      > Assuming you have something that came from the db stored in a
      > variable, then it's a simple case of telling html that there is a value
      > to be used, eg for text and textarea:
      >
      > $foo = "something from db"
      > $bar = "something very long from db"
      >
      > ...
      > <input type="text" name="short" value="$foo">
      > <textarea name="long">$ba r</textarea>
      > ...
      >
      > /Marcin[/color]

      Be sure that's written right, though... you can't just insert variables
      into straight HTML...

      (method 1)

      ....
      <input type="text" value="<?php echo $foo; ?>">
      <textarea><?p hp echo $bar; ?></textarea>
      ....

      (method 2)

      <?php
      ....
      echo "<input type=\"text\" value=\"$foo\"> \n";
      echo "<textarea>$bar </textarea>";
      ....
      ?>



      --
      -- Rudy Fleminger
      -- sp@mmers.and.ev il.ones.will.bo w-down-to.us
      (put "Hey!" in the Subject line for priority processing!)
      -- http://www.pixelsaredead.com

      Comment

      Working...