我有两个脚本做几乎相同的事情,但其中一个不工作。我只是想不出问题出在哪里。两个脚本的代码几乎相同,但“更新消息”脚本不起作用。我没有收到任何 php 错误,但数据库没有更新。
删除脚本(工作):
<?php
function deleterow()
{
$con=mysqli_connect("localhost","root","root","TP1AlexandreBouletCouture");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$delete_id = ($_GET["delete_id"]);
$sql="DELETE FROM `table1` WHERE `table1`.`id` = '$delete_id'";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo '<p>Message supprimé</p>';
mysqli_close($con);
}
if(isset($_GET['delete_id']))
{
deleterow($_GET['delete_id']);
}
?>
<form action="history.php" method="get">
<input type="submit" value="Supprimer">
<input type="hidden" name="delete_id" value='.$row['id'].'>
</form>
更新消息脚本(不起作用):
<?php
function updatemyinfos()
{
$con=mysqli_connect("localhost","root","root","TP1AlexandreBouletCouture");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$update_id = ($_GET["update_id"]);
$new_message = ($_GET["updatemessage"]);
$sql="UPDATE `table1` SET `message` = '$new_message' WHERE `table1`.`id` ='$update_id";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo '<p>Message modifié</p>';
mysqli_close($con);
}
if(isset($GET['updatemessage']))
{
updatemyinfos($GET['updatemessage']);
}
?>
<form action="history.php" method="get">
<textarea style="resize:none"cols="35"rows="3"name="updatemessage">'.$row['message'].'</textarea>
<input type="submit" value="Modifier">
<input type="hidden" name="update_id" value='.$row['id'].'>
</form>