Loading MySQL data into a form...

Associate
Joined
23 Mar 2009
Posts
348
Location
Midlands
Hey all.

I've made quite a cool little script, but have hit a dead end with my abilities!

I'm trying to create a form with about 40 odd text boxes which I need to load data from a SQL table for a relevant ID.

e.g.
If the persons name is Bob, then load all of bobs details into the form from Bob's row of data.

Get what I mean?

I think it should be done using arrays, but I have no idea how.

edit: PHP please :)
 
*bumpage*

It's basically a web form in HTML where I need to load the values into the text boxes from an MySQL database, but can't find an easyish way of doing it :(
 
PHP:
$query = mysql_query("SELECT name, age, height FROM tbl WHERE name='Bob'");
$query = mysql_fetch_array($query);

This will put all of Bob's rows into the $query array, then you can access them as below:

PHP:
$name = $query["name"];
$age = $query["age"];
$height = $query["height"];

And so on. Then to pre-populate the text boxes:

Code:
<input type="text" name="name" value="<?php echo $name; ?>" />
<input type="text" name="age" value="<?php echo $age; ?>" />
<input type="text" name="height" value="<?php echo $height; ?>" />

Hope that's what you're after. The syntax for the MySQL stuff may be wrong as I only use MSSQL with PHP but I'm sure you can adjust where necessary :p
 
Back
Top Bottom