消息框和查询已执行但更改未反映在数据库中

时间:2018-03-25 16:29:18

标签: javascript php html css

每当我按下启用或禁用按钮时,都会生成messagebox,表示查询已执行,但更改未反映在数据库中,并且在 phpmyadmin 中单独执行时的查询反映了结果进入数据库。我甚至尝试输出 mysqli_error()函数,但也没有回复任何错误。

<!doctype html>  
<html>  
<?php include'abcadmin.css' ?> 

<body>  
    <br>
    <br>
    <br>
    <br>
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    <br>
    <br>
    <br>
    <br>
     <center><h1></h1></center>  
 &nbsp;
&nbsp;

<form action="" method="POST">
<center><h4><b>Student Edit & Account Management</b></h4></center> <br> 
<center><h4>SAP ID: <input type="text" name="search"><br /></h4>  </center> 
&nbsp;
&nbsp;
<center><input type="submit" value="Search" name="submit" /> </center><br>
</form>  
<br>
<?php  
  session_start();
  global $a,$search,$b;
  $con=mysqli_connect('localhost','root','') or die(mysql_error());  
  mysqli_select_db($con,'sophomore') or die("cannot select DB");

  if(isset($_POST["submit"]))
 {   
  $search=$_POST['search'];
  $query=mysqli_query($con,"SELECT * FROM student_registration WHERE sap_id='".$search."'"); 
  $numrows=mysqli_num_rows($query);

  if($numrows>0)
  {
   if(!empty($_POST['search'])) 
    {   
    if($numrows!=0) 
while($row=mysqli_fetch_assoc($query))
{   
    {  
     $stuname=$row['fname'];
     $stusurname=$row['lname'];
     $stusapid=$row['sap_id'];
     $studob=$row['dob'];
     $stuage=$row['age'];
     $stucourse=$row['course'];
     $stusemester=$row['semester'];
     $stustatus=$row['status'];
     $_SESSION['adminstusapid']=$stusapid;
    }
    }
    }

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "Name: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stuname;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "Surname: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stusurname;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "SAP ID: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stusapid;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "DOB: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $studob;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "Age: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stuage;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "Course: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stucourse;
echo '</td>';
echo '</tr>';

echo '<h4><table align="center" width="">';
echo '<tr>';
echo '<td>';
echo "Semester: ";    
echo '&nbsp';
echo '</td>';
echo '<td>';
echo $stusemester;
echo '</td>';
echo '</tr>';

echo '</table>';
echo '</h4>';
echo '<br>';
echo '<form method="post">';
echo '<center>';
echo '<input type="submit" value="Enable" name="enabled">'; 
echo '&nbsp';
echo '&nbsp';
echo '<input type="submit" value="Disable" name="disabled">'; 
echo '</center>';
echo '</form>';
}
 else
 {
     echo "<script type='text/javascript'>alert('No results found!!')</script>";
 }
 }

$a=0;
$b=1;

if(isset($_POST["enabled"])){
    $sqla="UPDATE student_registration SET status='$stucourse' WHERE sap_id='".$search."'";
    if(mysqli_query($con, $sqla)){
        echo "<script type='text/javascript'>alert('The account has been enabled!!')</script>";
}
else
{
}
}
else
{
}

if(isset($_POST["disabled"])){
    $sqlb="UPDATE student_registration SET status='$b' WHERE sap_id='".$search."'";
    if(mysqli_query($con, $sqlb)){
        echo "<script type='text/javascript'>alert('The account has been disabled!!')</script>";
}
else
{
}
}
else
{
}

0 个答案:

没有答案