<?php
$title=$_POST['title'];
$author=$_POST['author'];
$content=$_POST['content'];
$sql_update="UPDATE news SET title='$title',author='$author',content='$content' WHERE id=".$id;if($_POST['submit']==true)
{if($update=mysql_query($sql_update) or die(mysql_error()))
{
echo "<script>alert('修改成功!');location.href('Newsmanage.php');</script>";
}
else
{
echo "<script>alert('修改失败');</script>";
}
}
?>
$title=$_POST['title'];
$author=$_POST['author'];
$content=$_POST['content'];
$sql_update="UPDATE news SET title='$title',author='$author',content='$content' WHERE id=".$id;if($_POST['submit']==true)
{if($update=mysql_query($sql_update) or die(mysql_error()))
{
echo "<script>alert('修改成功!');location.href('Newsmanage.php');</script>";
}
else
{
echo "<script>alert('修改失败');</script>";
}
}
?>
....
$id = (int)$id;
$sql_update="UPDATE news SET title='$title',author='$author',content='$content' WHERE id=".$id;
....
先:
echo $sql_update;
然后:
把输出的sql代码放到phpmyadmin里运行,看下提示什么错误,基本就能搞明白了,或者把提示的错误发过来看下
$id哪里给赋值了?如果是POST数据就改成 $id = (int)$_POST['id'];//$id为空值的话,下面语句不这样处理下就会出错
$sql_update="UPDATE news SET title='$title',author='$author',content='$content' WHERE id=".$id;
//or $sql_update="UPDATE news SET title='$title',author='$author',content='$content' WHERE id='".$id."'";