在我的PHP类中,我们必须显示数据库中的信息,然后才能删除条目或编辑条目。我正在使用WAMP和Sequel Pro。它可以毫无问题地显示信息,删除按钮可以正常工作,所以我知道它正在与数据库通信,但是我无法在数据库中更新信息。我尝试了许多错误报告方法,但没有错误。甚至代码说它可以做到这一点,它也可以做到。我尝试将其移动到代码中的不同位置,使其成为自己的区域,但是没有任何效果。我已经确保所有根特权都已检查,所以我知道这不是问题。因此,如果有人可以帮助我,我将不胜感激。
以下是更新代码本身:
if(isset($_POST['update_prof'])) {
$update_id = $_POST['update_prof'];
$ins_first_name = $_POST['ins_first_name'];
$ins_last_name = $_POST['ins_last_name'];
$ins_college = $_POST['ins_college'];
$ins_senority_date = $_POST['ins_senority_date'];
$update_prof = "UPDATE instructorInf SET
ins_first_name='$ins_first_name',
ins_last_name='$ins_last_name',
ins_college='$ins_college',
ins_senority_date='$ins_senority_date'
WHERE ins_id='$update_id'";
$run_update = mysqli_query($dbc, $update_prof) or die(mysqli_error());
//echo "<script>alert('Something Happened!')</script>";
//echo mysql_error();
// REFRESH PAGE ON UPDATE
if($run_update){
//echo "<script>alert('Professor has been updated!')</script>";
echo '<script>window.location = "http://localhost:8888/Lab6_Johnny_Bruner.php";</script>';
}
}
这是表格的代码:
<form action="'. $_SERVER['PHP_SELF'] .'" enctype="multipart/form-data" method="post">
<table width="500px"
style="padding-top:15px; padding-bottom:15px; border-bottom-width: thick; border-bottom-style: double; border-bottom-color: #EC008B;">
<tr>
<td rowspan="5" valign="middle" align="center" width="100px">
<input name="thisID" type="hidden" value="'. $ins_id .'"/>
<a href="?update_prof='. $ins_id .'" onclick="return confirm(\'Are you sure you want to UPDATE?\');">
<input class="button" type="submit" name="update_prof"
style="color:white; background-color:green; text-weight:bold;" value="UPDATE"/></a>
<a href="?delete_prof='. $ins_id .'" onclick="return confirm(\'Are you sure you want to DELETE?\');">
<input class="button" type="button" name="delete_prof" value="DELETE"/></a>
</td>
<td align="right" width="200px">
Professor ID:
</td>
<td>
<strong>'. $ins_id .'</strong>
</td>
</tr>
<tr>
<td align="right">
Professor First Name:
</td>
<td>
<input type="text" name="ins_first_name" value=" '. $ins_first_name .'"/>
</td>
</tr>
<tr>
<td align="right">
Professor Last Name:
</td>
<td>
<input type="text" name="ins_last_name" value=" '. $ins_last_name .'"/>
</td>
</tr>
<tr>
<td align="right">
College of:
</td>
<td>
<input type="text" name="ins_college" value=" '. $ins_college .'"/>
</td>
</tr>
<tr>
<td align="right">
Professor Senority:
</td>
<td>
<input type="text" name="ins_senority_date" value=" '. $ins_senority_date .'"/>
</td>
</tr>
</table>
</form>
这是完整的代码:
<!DOCTYPE HTML>
<html>
<head>
<title>CSC306 - Lab 6 - Johnny Bruner</title>
<style>
h1 {
text-align: center;
padding-top: 50px;
}
table {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// CONNECT TO DATABASE
$dbc = mysqli_connect("localhost", "root", "password", "CSC306Class");
if (mysqli_connect_errno()) {
echo "The Connection was not established: " . mysqli_connect_error();
}
// echo "Connected successfully";
// START FUNCTION TO GET STUDENT INFORMATION
function getProfessors(){
// CONNECT TO DB
global $dbc;
// UPDATE ENTRY
if(isset($_POST['update_prof'])){
$update_id = $_POST['update_prof'];
$ins_first_name = $_POST['ins_first_name'];
$ins_last_name = $_POST['ins_last_name'];
$ins_college = $_POST['ins_college'];
$ins_senority_date = $_POST['ins_senority_date'];
$update_prof = "UPDATE instructorInf SET
ins_first_name='$ins_first_name',
ins_last_name='$ins_last_name',
ins_college='$ins_college',
ins_senority_date='$ins_senority_date'
WHERE ins_id='$update_id'";
$run_update = mysqli_query($dbc, $update_prof) or die(mysqli_error());
//echo "<script>alert('Something Happened!')</script>";
//echo mysql_error();
// REFRESH PAGE ON UPDATE
if($run_update){
//echo "<script>alert('Professor has been updated!')</script>";
echo '<script>window.location = "http://localhost:8888/Lab6_Johnny_Bruner.php";</script>';
}
}
// CONNECT TO TABLE
$get_prof = 'SELECT * FROM instructorInf ORDER BY ins_id ASC';
$run_prof = mysqli_query($dbc, $get_prof);
$count_prof = mysqli_num_rows($run_prof);
if($count_prof==0){
echo '<h2 style=padding:20px;">No professors where found, Please check back soon!</h2>';
}
// FETCH INFORMATION
while ($row_prof_new=mysqli_fetch_array($run_prof)) {
$ins_id = $row_prof_new['ins_id'];
$ins_first_name = $row_prof_new['ins_first_name'];
$ins_last_name = $row_prof_new['ins_last_name'];
$ins_college = $row_prof_new['ins_college'];
$ins_senority_date = $row_prof_new['ins_senority_date'];
// DISPLAY INFORMATION
echo '<form action="'. $_SERVER['PHP_SELF'] .'" enctype="multipart/form-data" method="post">
<table width="500px" style="padding-top:15px; padding-bottom:15px; border-bottom-width: thick; border-bottom-style: double; border-bottom-color: #EC008B;">
<tr>
<td rowspan="5" valign="middle" align="center" width="100px" >
<input name="thisID" type="hidden" value="'. $ins_id .'" />
<a href="?update_prof='. $ins_id .'" onclick="return confirm(\'Are you sure you want to UPDATE?\');" >
<input class="button" type="submit" name="update_prof" style="color:white; background-color:green; text-weight:bold;" value="UPDATE" /></a>
<a href="?delete_prof='. $ins_id .'" onclick="return confirm(\'Are you sure you want to DELETE?\');" >
<input class="button" type="button" name="delete_prof" value="DELETE" /></a>
</td>
<td align="right" width="200px">
Professor ID:
</td>
<td>
<strong>'. $ins_id .'</strong>
</td>
</tr>
<tr>
<td align="right">
Professor First Name:
</td>
<td>
<input type="text" name="ins_first_name" value=" '. $ins_first_name .'" />
</td>
</tr>
<tr>
<td align="right">
Professor Last Name:
</td>
<td>
<input type="text" name="ins_last_name" value=" '. $ins_last_name .'" />
</td>
</tr>
<tr>
<td align="right">
College of:
</td>
<td>
<input type="text" name="ins_college" value=" '. $ins_college .'" />
</td>
</tr>
<tr>
<td align="right">
Professor Senority:
</td>
<td>
<input type="text" name="ins_senority_date" value=" '. $ins_senority_date .'" />
</td>
</tr>
</table>
</form>';
}
// DELETE ENTRY
if(isset($_GET['delete_prof'])){
$delete_id = $_GET['delete_prof'];
$delete_prof = 'DELETE FROM instructorInf WHERE ins_id='. $delete_id. '';
$run_delete = mysqli_query($dbc, $delete_prof);
// REFRESH PAGE ON DELETE
if($run_delete){
echo '<script>window.location = "http://localhost:8888/Lab6_Johnny_Bruner.php";</script>';
}
}
}?>
<body>
<h1>Student Information</h1>
<?php //getStudents(); ?>
<h1>Professor Information</h1>
<?php getProfessors(); ?>
<h1>Reviews</h1>
<?php //getReviews(); ?>
</body>
</html>
在此先感谢您的帮助!