php修改公告,每次修改一条,所有记录都会变,高手看下什么问题

2025-02-03 03:04:04
推荐回答(4个)
回答1:

1、你传递的是ID,但是在数据库查找的时候是title
2、在你保存的时候没有选择修改哪条记录,默认是修改所有的
下边是我帮你修改过的
$title = $_POST['title'];
$content= $_POST['content'];
$time = $_POST['time'];
$id = $_POST['id'];
if(isset($_POST["submit"]))
{

if($title!="" && $content!="" ){
$sql= "update affiche set title='$title',content='$content' where id=$id"; '保存内容和标题,条件是传入的ID值
$result = mysql_query($sql,$conn);
}
if ($result){
echo "";
}
else{
echo "";
}
mysql_close($conn); //关闭数据集
}

?>
URL传递部分:
include("../conn.php");
$eee= $_GET['id']; ‘这里传入的是ID
$sql="select * from affiche where id='$eee'"; ’这里查找也应该是ID
$query=mysql_query($sql,$conn);
$rs=mysql_fetch_array($query);

?>

回答2:

你update的时候,选择条件都没加,当然是更新全表记录了,好歹有个where id=$id

回答3:

update 语句需要加个where 条件吧

回答4:

$sql= "update affiche set title='$title'";这句我看不明白了,
$sql= "update affiche set title='$title' where `字段名`=“某值”;