gpt4 book ai didi

php - 当前页面通过php更新Mysql中的数据

转载 作者:行者123 更新时间:2023-11-29 11:21:09 25 4
gpt4 key购买 nike

嘿,我在从前端 php 更新 MYSQL 中的数据时遇到问题,当我单击一次时,它会更新数据,当我再次单击时,没有任何更改,它会再次更新并带来以前的数据。我是 php 初学者,不知道问题是什么,因为代码没有错误,也没有警告,请帮助和指导,感谢您提前抽出时间

我的代码是

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Update in PHP</title>
</head>
<body>


<?php
$servername="localhost";
$username="root";
$password="";
$conn=mysql_connect($servername,$username,$password);

if(!$conn ) {
die('Could not connect: ' . mysql_error());
}

$sq1 = 'select * from biodata';
mysql_select_db('firstdb');
$display=mysql_query($sq1,$conn);

if(!$display ) {

die('Could not get data: ' . mysql_error());
exit;
}

if (mysql_num_rows($display) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
?>


<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>ID</th>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Phone</th>
<th>Message</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $display ) ){
echo
"<form method= 'post' />
<tr>
<td><input name='UID' value='{$row['ID']}' /></td>
<td><input name='upfname' value='{$row['fname']}' /></td>
<td><input name='uplname' value='{$row['lname']}' /></td>
<td><input name='upemail' value='{$row['email']}' /></td>
<td><input name='upphone' value='{$row['phone']}' /></td>
<td><input name='upmessage' value='{$row['message']}' /></td>
<td><input type='Submit' name='update' value='Update' id='".$row["ID"]."' </td>
</tr>
</form>";
}
?>
</tbody>
</table>
<?php
if(isset($_REQUEST['update']))
{

$id = $_REQUEST['UID'];
$upfn = $_REQUEST['upfname'];
$upln = $_REQUEST['uplname'];
$upem = $_REQUEST['upemail'];
$upph = $_REQUEST['upphone'];
$upms = $_REQUEST['upmessage'];

$up="UPDATE biodata
SET
fname='$upfn',
lname='$upln',
email='$upem',
phone='$upph',
message='$upms'
WHERE ID = $id";
$updbb=mysql_query($up,$conn);




}
?>

</body>
</html>

最佳答案

重定向同一页面

header('位置:url'); like header('位置:inbox.php?u='.$log_username.'');

关于php - 当前页面通过php更新Mysql中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com