我有两个脚本做几乎相同的事情,但其中一个不起作用。我只是不知道问题出在哪里。这两个脚本具有几乎相同的代码,但“更新消息”脚本不起作用。我没有收到任何 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>
最佳答案
$update_id
后缺少引号。
'$new_message' WHERE `table1`.`id` ='$update_id
但是你应该使用 PDO,http://php.net/manual/en/book.pdo.php . mysql 扩展已从 php 5.5.0 开始弃用
关于php - 我不明白为什么这些 PHP 脚本之一不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19503735/