I have a site that has forms to insert, delete and update records for a database.
I have no problem inserting and deleting records, but I can't seem to put the UPDATE working. What am I doing wrong?
HTML
<form class="about-form" action="" method="POST">
<p class="title">About</p>
<textarea class="textarea" name="text" rows="8" cols="80" disabled><?php echo $about->content_text; ?></textarea><br>
<input class="edit-button" type="button" name="edit" value="Edit">
<input type="submit" name="save" value="Save" class="save-button">
</form>
PHP
//get a content text from the database
$about = $db->get_single_row("SELECT * FROM content WHERE content_id='2'");
if(isset($_POST['save'])) {
$aboutText = $_POST['text'];
$db->query("UPDATE content SET content_text='$aboutText' WHERE content_id='2'");
}
The error message I get is this: "Notice: Undefined index: text"
UPDATE: I have two buttons, one to edit (that removes the disabled) and one to save(puts back disabled and submits). I managed to do the UPDATE after removing the javascript of the button "save". Managed to UPDATE after removing javascript for the save button. How can i put the disabled or readonly after submitting the form?
Your element named "text" is disabled, so will not post on submission. I suspect the problem you're having is that $_POST['text'] is blank, but you weren't clear what error (if any) you were seeing.
Why did you put the disabled attribute to the text area ?
If that does not work. It seems like your textarea input field is not linked with the form. so add a name attribute to the form then add a form attribute to the textarea with value to name of the form.
<form class="about-form" action="" method="POST" name="myform">
<p class="title">About</p>
<textarea class="textarea" name="text" rows="8" cols="80" form="myform" disabled><?php echo $about->content_text; ?></textarea><br>
<input class="edit-button" type="button" name="edit" value="Edit">
<input type="submit" name="save" value="Save" class="save-button">
</form>
so please put the error message u got after trying.
disabled input will not submit data.
Use the readonly attribute:
<textarea class="textarea" name="text" rows="8" cols="80" readonly >
Thank you for all the replies.
I Managed to fix it by substituting disabled for readonly. But the main problem was the "save" button witch was putting back the disabled attribute before submitting the query