I have this function, its purpose is to update a post. I have another function that pulls the data from the database and displays it between <form> tags and the action will direct to a update.php file which includes the following:
<?php
include_once("functions.php");
$obj = new data_handler;
$obj->update_post($_GET['id']);
?>
Then this is run:
public function update_post($id) {
try {
$sql = $this->con->prepare("UPDATE Content SET Title=?, Body=? WHERE id=?");
$sql->bindParam(1, $_POST['title']);
$sql->bindParam(2, $_POST['body']);
$sql->bindParam(3, $id);
$sql->execute();
} catch (PDOException $e) {
echo $e->getMessage();
}
header("Location: index.php");
}
This is the function that pulls the content to edit:
public function display_selected ($id) {
$sql = $this->con->query("SELECT * FROM Content WHERE id= '$id'");
while ($row = $sql->fetch()) {
echo $row['Body'];
}
}
This is the form:
<form action="update.php" method="post">
<input type="text" size="105" name="title"></input>
<textarea name="body"><?php $obj = new data_handler; $obj->display_selected($_GET['id']); ?></textarea>
<input type="submit" value="Update"/>
</form>
I get no errors/exceptions/warnings, I can go through the whole process, but it does not change anything.
Option 1
change
to
and add this to your form
It’s worth noting: input tags are self closing, so you don’t need at the end.
Option 2
change
to