所以我有这个从数据库加载数据的表单,我想使用更新查询保存用户在数据库中修改的新数据但我的代码实际上删除了字段中的所有数据而不是保存更改我制作...我不知道为什么......这是代码:
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";
}
以下是表格:
<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>
任何想法?