php - 使用输入更新 phpmyadmin 中的表

标签 php mysql sql

我一直在尝试为我的大学建立一个在线网关,工作人员可以在其中提名学生获得特定的职位或奖项。我使用 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 &nbsp </th>
<th>Name &nbsp &nbsp &nbsp </th>
<th>Class &nbsp </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/

相关文章:

php - 安装 ruby​​ 会降低我的 vps 速度吗?

php - 使用 PHP 将数据库结构插入 MySQL?

php - 如何更新特定 ID 以接受或拒绝用户

javascript - 对 MySQL 运行数据库查询后无法看到结果

php - 在 solr/lucene 中过滤存储在远程数据库中的字段的最佳方法?

php - 由连字符和下划线连接的单词的正则表达式,同时保留标点符号

PHP 脚本超时

SQLite 语法错误(从 PostgreSQL 转换)

sql - 在 SQL Server 中高效查询图边的有向/无向表

mysql - Yii2:如何从 'date' db 列中按 'time' 和 'datetime' 进行过滤