473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 20919
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.