By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mark wrote:
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?


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">$bar</textarea>
....

/Marcin

Jul 17 '05 #2

P: n/a
Regarding this well-known quote, often attributed to Marcin Dobrucki's
famous "Wed, 03 Dec 2003 16:39:43 GMT" speech:
Mark wrote:
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?


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">$bar</textarea>
...

/Marcin


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><?php echo $bar; ?></textarea>
....

(method 2)

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

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.