Jump to content

Text field with variable stored in database


kfarrar

Recommended Posts

I have a page where a user builds a custom form line by line by selecting a variety of “form elements” on a self submitting page. These form elements are just HTML tables with multiple <input type=”text”> or <textarea>’s which are stored in the MySQL database.

 

Once the user has built the form then they fill in the text areas of each line and save the completed form. The data from each line is saved to the database.

 

The problem is I can’t seem to populate the text areas on the form for viewing because my form inputs have a variable for value=”$example”.

 

EXAMPLE:

If this was on my page of code it will work and echo the contents of field1 into the text area. <textarea name="line_item[]"><?echo $got->field1;?></textarea>

 

But when the same html as above comes from the database then the text area is populated with this  <?echo $got->field1;?>

 

What do I do?

 

Here is the PHP that echo’s the form:

 

 

$query = ("SELECT * FROM auto_save ORDER BY line_order ASC");

$result = mysql_query($query) or die(mysql_error());

 

$line_order = 1.0;

 

while($row = mysql_fetch_array($result)) {

 

$get_one = mysql_query("SELECT * FROM auto_save WHERE line_order = $line_order");

$got = mysql_fetch_object($get_one);

 

//echo "$got->field1 $got->field2 $got->field3 $got->field4 $got->field5";

 

echo '<table><tr><td width=50 class=linenumber>'.$row['line_order'].'</td><td>'.$row['form'].'</td></tr></table>';

 

$line_order = $line_order + 1.0;

 

}

you're only retrieving one row from the DB.

you need to use a while loop to cycle through all the returned DB  rows.

i.e.look here

$result = mysql_query("select * from mytable");

while ($row = mysql_fetch_object($result)) {

    echo $row->user_id;

    echo $row->fullname;

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.