我一直在尝试为我的大学建立一个在线网关,工作人员可以在其中提名学生获得特定的职位或奖项。我使用 php 和 css 作为前端,使用 phpmyadmin 作为后端。但是,一旦我输入(regno)来提名学生,它就不会在表中更新。有人可以帮忙吗?这是我的代码:
<!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=UTF-8">
<title>NOMINATE ENTRIES</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Nominate Entries</a></h1>
<form name="form5" class="appnitro" method="post" action="test.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","staff","12345","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM `student` WHERE `Nominated` = 0");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Department   </th>
<th>Name       </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
if(isset($_POST['submit']))
{
$regno = $_POST['regno'];
$reason = $_POST['reason'];
$sql = "UPDATE `mop`.`student` SET `Nominated` = \'1\' WHERE `student`.`RegNo` = 1106103;";}
mysqli_close($con);
?>
</center></font>
</p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" id="regno" name="regno"><br>
<b>Enter Reason <font color='red'>*</font> </b> <input type="text" id="reason" name="reason"><br>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
最佳答案
您实际上并未发送查询。
$result = $connection -> query($sql);
// Or, since it is only an update
$connection -> query($sql);
其中$connection
是与数据库的连接
关于php - 使用输入更新 phpmyadmin 中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21095454/