我是 PHP 新手,我想对这个小脚本进行一些输入。一切似乎都有效,但我需要知道如何检索已修改消息的“id”。
<?php
function updatemyinfos() {
$con=mysqli_connect("localhost","root","root","dbname");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
**$id=**
$sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo '<p>Message modifié</p>';
mysqli_close($con);
}
if(isset($_POST['updatemessage']))
{
updatemyinfos();
}
?>
<form action="#" method="post">
<textarea style="resize:none" cols="1" rows="1" name="message"id="textbox">'.$row['message'].'</textarea>
<input type="submit" value="Soumettre" name="updatemessage" id="updatemessage">
</form>
编辑:我试过这个..我没有收到任何错误消息,但数据库没有更新。但我得到了“回声”
消息修改
"<?php
function updatemyinfos($id) {
$con=mysqli_connect("localhost","root","root","TP1AlexandreBouletCouture");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="UPDATE table1 SET message = '$_POST[message]' WHERE id ='$id'";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo '<p>Message modifié</p>';
mysqli_close($con);
}
if(isset($_POST['updatemessage']))
{
updatemyinfos($_POST['updatemessage']);
}
?>