so i have this form that loads data from the database and i want to save the new data that the user modifies in the database using the update query but my code actually deletes all the data in the fields instead of saving the changes i make... and i don t know why... here is the code:
if(!empty($_POST['titlu']) && !empty($_POST['descriere']) && !empty($_POST['text_poveste']))
{
$stmt = $conn->prepare("UPDATE `stories` SET `title` = :title, `story_description` = :story_description, `story_text` = :story_text WHERE `id_story`=:id_story");
$stmt->bindParam(':id_story', $_GET['id'], PDO::PARAM_INT);
$stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$stmt->bindParam(':story_description', $_POST['story_description'], PDO::PARAM_STR);
$stmt->bindParam(':story_text', $_POST['story_text'], PDO::PARAM_STR);
if($stmt->execute()){
$message = "POVESTEA A FOST ACTUALIZATA";}
else {
$message = "EROARE";
}
and here is the form:
<form action="edit_data.php?id=<?php echo $_GET[id]; ?>" method="POST">
<input type="text" name="titlu" placeholder="titlu" value="<?php print_r($story_data[0]->title)?>" required>
<textarea name="descriere" rows="5" cols="40" placeholder="descriere" required><?php print_r($story_data[0]->story_description)?></textarea>
<textarea name="text_poveste" id="editor1" placeholder="text_poveste" rows="10" cols="60" required><?php print_r($story_data[0]->story_text)?></textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
any ideas?
Aucun commentaire:
Enregistrer un commentaire