473,320 Members | 2,177 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,320 software developers and data experts.

How do I use a variable to fill a form with MySQL record data?

Hello,
I am trying to make a PHP/HTML update script for MySQL.

I prompt the user to enter the ID# of the record they wish to update into a form which then uses the passed ID# to select the associated record from the database:

Expand|Select|Wrap|Line Numbers
  1. $id = @$_GET['q'] ;
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT FROM Hcffres WHERE residentid = $id";
  2. mysql_query($query);
How do I output the data from the query into the form so the user simply alters the field that needs to be updated? I've tried variations of this:

Expand|Select|Wrap|Line Numbers
  1. Last Name: </font></td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>"  size="40"</td></tr>
but atm I get a blank form and when I try to input any data the residentid = 0 not the passed variable

-- thanks for any help --
Apr 5 '07 #1
8 3034
ak1dnar
1,584 Expert 1GB
Hello,
I am trying to make a PHP/HTML update script for MySQL.

I prompt the user to enter the ID# of the record they wish to update into a form which then uses the passed ID# to select the associated record from the database:

Expand|Select|Wrap|Line Numbers
  1. $id = @$_GET['q'] ;
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT FROM Hcffres WHERE residentid = $id";
  2. mysql_query($query);
How do I output the data from the query into the form so the user simply alters the field that needs to be updated? I've tried variations of this:

Expand|Select|Wrap|Line Numbers
  1. Last Name: </font></td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>"  size="40"</td></tr>
but atm I get a blank form and when I try to input any data the residentid = 0 not the passed variable

-- thanks for any help --

[PHP]$id = $_GET['q'] ;


$query = "SELECT * FROM Hcffres WHERE residentid = '$id'";
mysql_query($query);
[/PHP]
Apr 6 '07 #2
Motoma
3,237 Expert 2GB
I usually build an array returning PHP function:

[php]
function query($qry)
{
$res = mysql_query($qry);
$ret = array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_BOTH))
if($row)
$ret[$i++] = $row;
return $ret;
}
[/php]
Apr 6 '07 #3
thanks for the replies but the problem remains:
[php]
$query = "SELECT * FROM hcffres WHERE residentid = $var";
mysql_query($query);
// I need to know what command goes here
echo"<form action=....
[/php]
what is the command I need to output the data returned from the query into the html form so the user can alter the field that needs updating

here's hoping...
Apr 6 '07 #4
Motoma
3,237 Expert 2GB
what is the command I need to output the data returned from the query into the html form so the user can alter the field that needs updating
Did you even attempt to look at my last post? I provided a function which will return the entire dataset in an associative array for easily accessing your MySQL record set.
Apr 7 '07 #5
ak1dnar
1,584 Expert 1GB
thanks for the replies but the problem remains:
[php]
$query = "SELECT * FROM hcffres WHERE residentid = $var";
mysql_query($query);
// I need to know what command goes here
echo"<form action=....
[/php]
what is the command I need to output the data returned from the query into the html form so the user can alter the field that needs updating

here's hoping...
[PHP]
$query = "SELECT * FROM hcffres WHERE residentid = $var";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );
echo 'other stuffs';
echo '<input type="text" name="name_goes_here" value="'.$row['column_name_here'].'"/>';[/PHP]
Apr 7 '07 #6
thanks for the replies, I didn't get it to work but I went round the problem.

i saw the function, thanks, but I wanted to know how to fix that specific problem.

of course I have a new problem now with JS form validation
avaialble at: http://www.thescripts.com/forum/show...20#post2492320 if anyone's interested.
Apr 8 '07 #7
Motoma
3,237 Expert 2GB
...
i saw the function, thanks, but I wanted to know how to fix that specific problem.
...
Well, the function I gave you shows exactly how to solve your problem. Your problem was that you were not actually retrieving any of the information after you performed a query.
Apr 9 '07 #8
dzuse
2
Well, the function I gave you shows exactly how to solve your problem. Your problem was that you were not actually retrieving any of the information after you performed a query.
you can add wxtract function in the end ;)

$query = "SELECT * FROM hcffres WHERE residentid = $var";

$result = mysql_query($query);

$row = mysql_fetch_array( $result );
extract($row;
echo 'other stuffs';

echo '<input type="text" name="name_goes_here" value="$column_name_here"/>';
Apr 9 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Iain Miller | last post by:
I'm sure this ought to be simple but I can't make it work!! I have a form (based on a query) that holds information about an individual. Each individual has a Unique reference field called...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
5
by: Jim via DotNetMonster.com | last post by:
Hi, I need to pass the value of a variable from one function to another but I don't seem to get the value. I declare the variable outside all functions. What I'm trying to do is that when the...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
4
by: Garry Jones | last post by:
I want to Select a field based upon the number the user keys in I want to retrieve another field from the same record This is not working. How do I do it? The tricky bit seems to me to be...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.