使用输入更新phpmyadmin中的表

使用输入更新phpmyadmin中的表,php,mysql,sql,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"> &

我一直在尝试为我的学院建立一个在线门户,在那里工作人员可以提名学生担任特定职位或奖项。我使用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
是到您的数据库的连接

我已经像这样更改了整个文件,先生。感谢所有您的意见,希望与他人分享:

这是我的form.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=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="form" 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","123456","mop");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM student");

echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Name &nbsp &nbsp &nbsp </th>
<th>Department &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>";

mysqli_close($con);
?>
</center></font>
            </p>
        </div>  
        <b>Enter Register Number <font color='red'>*</font> </b> <input type="text" name="regno"><p>
        <b>Enter Reason <font color='red'>*</font> </b> <input type="text" name="reason"><p>

                    <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>

提名参赛作品
提名参赛作品
学生数据库

输入注册号* 输入原因*
它引用test.php文件,下面也是该文件:

<?php
$con=mysqli_connect("localhost","staff","123456","mop");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$sql1="UPDATE student SET Reason = '$_POST[reason]' WHERE RegNo ='$_POST[regno]'";
if (!mysqli_query($con,$sql1))
  {
  die('Error: ' . mysqli_error($con));
  }
  else
  {
   $sql2="INSERT INTO nominated select * from student where regno = '$_POST[regno]'";
   if (!mysqli_query($con,$sql2))
    {
    die('Error: ' . mysqli_error($con));
    }
    else
    {
    $sql3="DELETE from student where regno = ".intval($_POST["regno"]);
    if (!mysqli_query($con,$sql3))
   {
    die('Error: ' . mysqli_error($con));
   }
  }
 }
header("location:form5_1.php");

mysqli_close($con);
?>

错误消息是什么?同时显示您的表单请注意,phpmyadmin不是一个数据库:MySQL是一个包含表和索引内容的数据库,而phpmyadmin只是一个可以与之一起使用的客户端脚本:您的PHP代码访问MySQL,不是phpmyadminyes我使用phpmyadmin运行mysql。已将问题更新为我的完整表单。我实际上已将其连接。请参阅我的完整代码,我已再次更新我的问题。@YeshwanthVShenoy,您没有像对select查询那样执行更新后的查询。在变量中分配查询后,您应该使用mysql执行它。\u query I can get u sir您可以解释更多吗?在准备好查询字符串后(在本例中为$sql之后),您必须调用查询函数。您使用SELECT语句完成了这项操作,并将其排列了几行。。这是一行代码,您可以在其中明确告诉计算机要“运行”查询。另外,可能不太重要,但表的列标题和表行不匹配。输出部门名称,反之亦然