Hi everyone,
Noob here. I am having difficulties with retrieving data from a text field in my database. I am saving that to a hidden field and then printing the value inside of a textarea field in my form. The user will then be able to edit the text and update it in the database.
I'm not sure why, but when I retrieve the text from the database my textarea field from the form shows up blank on my page. If I type text in the field and click update, nothing is saved to the database. This form works with data saved in VARCHAR and INT fields in the database, but not with a textarea in my form.
I'm not sure, but does text db information not work when placed in a hidden field? Do I have to do something different when retrieving information from a text field in a db?
Any feedback would be greatly appreciated. Thanks!
Here is my code:
<?php
print "<table align=\"center\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">";
if($_SERVER['REQUEST_METHOD']=='POST') {
$isbn = $_POST['isbn'];
} else {
$isbn = $_GET['isbn'];
$sql = "SELECT isbn, artist_name, album_title, date_format(release_date, '%Y-%m-%d') as release_date, date_format(add_date, '%M %d, %Y') as add_date, description, price FROM lounge WHERE isbn = $isbn";
$rows = $db->getAll($sql);
foreach ($rows as $row) {
<input type=\"textarea\" name=\"description\" value=\"$row[description]\">
}
}
if ($_POST['_submit_check']) {
// If validate_form() returns errors, pass them to show_form()
process_form();
}
?>
<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
<tr><td>Description:<input type="textarea" name="<?php print $row[description]; ?>" size="11" maxleng="11"></td></tr>
<input type="hidden" name="isbn" value="<?php print $isbn; ?>" />
<tr><td colspan="2" align="center"><?php input_submit('save','Update'); ?>
</td></tr>
</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>
<?php
function process_form() {
$description = $_POST['description'];
$sql_update = "UPDATE lounge SET artist_name='$artist_name', album_title='$album_title', release_date='$release_date', add_date='$add_date', description='$description', price='$price' WHERE isbn = $isbn";
$db->query($sql_update);
}
?>