472,958 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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
Jul 17 '05 #1
2 20878
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: C. David Rossen | last post by:
Hello: I have a registration form for classes. Each class has a fee. I have a drop down box whereby the user chooses his class. There is a textbox with the associated fee. I would like to...
4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
4
by: anonymous | last post by:
Hi Folks, I have a form with two Dropdown list boxes, which get loaded with data from Database. DropDownList1 gets data from Table1 and DropDownList2 gets data from Table2 Table1 has a...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
6
by: Lodovikus | last post by:
So far I understand the concept of sending a form to email using PHP, In this case as I understood it, using two separate pages of code, one html form and the other one php code page, combined them...
10
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type...
6
by: robtyketto | last post by:
Greetings, Im a newbie to JSP/Javascript (unfortunalley). However I found enough example to create code that connects to my access db and populates two combo boxes. The selection of the...
8
by: freelance71 | last post by:
I have a combo box (select) and when the user selects a value I want to populate an HTML table from DB depending on the value selected. Whats the easiest way to achieve it. I've searched google and...
2
by: malcster2 | last post by:
hello, i am a beginner to ajax. i have created a mysql database, which i would like to access from a web page. i have created 3 files, a html to display the data, a php file to extract the data,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.