【发布时间】:2020-07-26 11:00:51
【问题描述】:
我在单击按钮时将数据从“请求”表传输到“用户”表时遇到问题,
这是 adminApprove.php,管理员将在其中单击“传输数据”按钮:
<!DOCTYPE html>
<html>
</html>
<head>
</head>
<body>
<h1 align="center">User List To be Approved</h1>
<br>
<table border='1' align="center">
<thead>
<tr>
<th align="center">Name</th>
<th>Address</th>
<th>Phone</th>
<th>Action</th>
</tr>
</thead>
<?php
// connect to the database
include('dbconfig.php');
// get record from db
$sql = "SELECT id, username, addr, phone from requests";
$result = $mysqli-> query($sql);
if ($result->num_rows > 0){
while ($row = $result-> fetch_assoc()){
echo "<tr><td>". $row["username"] ."</td>
<td>". $row["addr"] ."</td>
<td>". $row["phone"]. "</td>
<td>". "<a href='approve.php'" . $row["id"] . "'>Transfer Data</a>".
"</td></tr>";
}
echo "</table>";
}
else {
echo "No data to display";
}
$mysqli->close();
?>
</table>
</body>
</html>
然后将转到approve.php,其中sql查询从表'request'移动到'user'表:
<?php
include('dbconfig.php');
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
//$id = $_GET['id'];
$sql = "SELECT username, addr, phone, pwd from requests'";
$query = $mysqli->query($sql);
if(mysqli_num_rows($query) >= 1){
while ($row = $result-> fetch_assoc()){
$username = $row['username'];
$addr = $row['addr'];
$phone = $row['phone'];
$pwd = $row['pwd'];
$sql = "INSERT INTO user (username, addr, phone, pwd) VALUES ('$username', '$addr', '$phone','$pwd'";
echo "<script type='text/javascript'>alert('success');
window.location = '';</script>";
}
}else{
echo "<script type='text/javascript'>alert('Failed');
window.location = 'home.php';</script>";
}
$mysqli->close();
}
?>
当我点击按钮时,它没有弹出任何错误,并且数据没有传输,非常感谢任何帮助,谢谢..
【问题讨论】:
-
你有很多基本的 php & mysql 错误。
<a href='approve.php'" . $row["id"] . "'>应该是. 2. Inwhile ($row = $result-> fetch_assoc()){`, $result没有定义。还有很多其他的