Jump to content

Displaying database content in a HTML form


bluedot

Recommended Posts

Hey,
Is it possable to have the contents of a database row be displayed as the initial value in a html form?

somoething like:
<input name="date" type="text" id="date" value="$row[date]" maxlength="30" />
but of course html does not except $row[date] as a variable, it just prints "$row[date]"

Thank you very much!
Link to comment
Share on other sites

I've used both methods and both work but i've had better success with this method coming from a 'while' loop:


[code]<?php
while ($row = mysql_fetch_array($results)) {
 
echo " [i](then place all your form fields here like in a table)[/i]
<input type='text' size='40' name='URL' value='" . $row['URL'] . "'>
?>[/code]

Here's a full working example so you can see how the 'echo' displays everything:

[code]<?php
echo "
<form action='update.php' method='POST' name='updateProduct'>
<table width='780' border='0' bgcolor='#E1E1E1' padding='2'>
<tr><td>
<table width='100%' border='0'>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Product URL:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='40' name='URL' value='" . $row['URL'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Product ID:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Product_ID' value='" . $row['Product_ID'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Product Name:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Product_Name' value='" . $row['Product_Name'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Price:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Price' value='" . $row['Price'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Sale Price:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Sale_Price' value='" . $row['Sale_Price'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Description:
</td><td width='60%' bgcolor='#9AC5C5'><textarea cols='50' rows='5' name='Description' >" . $row['Description'] . "</textarea></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Category:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='40' name='Category' value='" . $row['Category'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Detail Image (full url):
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='60' name='Image' value='" . $row['Image'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Postage:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Postage' value='" . $row['Postage'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Brand:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Brand' value='" . $row['Brand'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Availability:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='Availability' value='" . $row['Availability'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Thumbnail Image (full url): 
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='60' name='Thumbnail' value='" . $row['Thumbnail'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Thumbnail width:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='ThumbnailWidth' value='" . $row['ThumbnailWidth'] . "'></td>
</tr>
<tr>
<td width='40%' bgcolor='#FFFFF'>
<font class='bodytextbold'>Thumbnail height:
</td><td width='60%' bgcolor='#9AC5C5'><input type='text' size='20' name='ThumbnailHeight' value='" . $row['ThumbnailHeight'] . "'></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='Add Product'> <input type='reset' name='reset' value='Clear'></td>
</tr>
</table>
</form>
</p>";
?>[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.