通过以下代码,我正在更新已存储在数据库中的数据。但是,当我点击我的更新按钮时,它显示以下错误:
“您的SQL语法中有错误;请查看与您的MariaDB服务器版本对应的手册,以便使用正确的语法,特别是在第1行的”执行阶段“ ”
我不知道为什么只有在我的内容('或')中有撇号时才显示此错误。对于那些有撇号的单词,它显示错误 不要,你是等等,在插入过程中它没有显示,但在更新过程中,它正在显示。
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$edit_query = "select * from blogs where blog_id= '$edit_id' ";
$run_edit = mysql_query($edit_query)or die(mysql_error());
while ($edit_row=mysql_fetch_array($run_edit)){
$blog_id = $edit_row['blog_id'];
$blog_title = $edit_row['blog_title'];
$blog_author = $edit_row['blog_author'];
$blog_image = $edit_row['blog_image'];
$blog_content = $edit_row['blog_content'];
}
}
?>
<form method="post" action="edit_blog.php?edit_form=<?php echo $edit_id; ?>" enctype="multipart/form-data">
<table width="600" bgcolor="orange" align="center" border="10">
<tr>
<td align="center" bgcolor="yellow" colspan="6"><h1>Edit The Blog Here</h1></td>
</tr>
<tr>
<td align="right">Blog Title:</td>
<td><input type="text" name="title" size="30" value="<?php echo $blog_title; ?>"></td>
</tr>
<tr>
<td align="right">Blog Author:</td>
<td><input type="text" name="author" size="30"value="<?php echo $blog_author; ?>"></td>
</tr>
<tr>
<td align="right">Blog Image:</td>
<td>
<input type="file" name="image" >
<img src="../imaged/<?php echo $blog_image;?>" width="100" height="100"> </td>
</tr>
<tr>
<td align="right">Blog Content:</td>
<td><textarea name="content" cols="30" rows="15"><?php echo $blog_content; ?></textarea></td>
</tr>
<tr>
<td align="center" colspan="6"><input type="submit" name="update" value="Update Now"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['update'])){
$update_id = $_GET['edit_form'];
$blog_title1 = $_POST['title'];
$blog_date1 = date('y-m-d');
$blog_author1 = $_POST['author'];
$blog_content1 = $_POST['content'];
$blog_image1= $_FILES['image']['name'];
$image_tmp= $_FILES['image']['tmp_name'];
if($blog_title1=='' or $blog_author1=='' or $blog_content1=='' or $blog_image1==''){
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else {
move_uploaded_file($image_tmp,"../imaged/$blog_image1");
$update_query = "update blogs SET blog_title='$blog_title1',blog_date='$blog_date1',blog_author='$blog_author1',blog_image='$blog_image1',blog_content='$blog_content1' where blog_id='$update_id' ";
if(mysql_query($update_query) or die(mysql_error())){
echo "<script>alert('blog has been updated')</script>";
echo "<script>window.open('view_blog.php','_self')</script>";
}
}
}
?>