我必须创建一个程序,允许用户从讲师表中删除更新讲师。由于某种原因,我的程序显示的表格不准确(例如,比当前表格更旧的值)。我无法删除或更新。我已经坚持了很长一段时间,并且如果这是一个简单的解决方案我只是一个初学者而道歉。
<?php
//includes
include("CONFIG/connection.php"); //include the database connection
include("LIBRARY/helperFunctionsTables.php"); //include the database connection
include("LIBRARY/helperFunctionsDatabase.php"); //include the database connection
require_once("CONFIG/config.php"); //include the application configuration settings
?>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;" charset="UTF-8">
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo __CSS; ?>
</head>
<body>
<header>
</header>
<?php
include("PAGE_CONTENT/navigation.php");
//----------------MAIN SECTION----------------------------//
//========================================================//
echo "<section class='wide'>";
$table = 'lecturer'; //table to delete records from
$PK = "LectID"; //Specify the PK of the table
if (isset($_POST['delrecord'])) //if the form has been submitted
{
//DELETE query
$selectedID = $_POST['delrecord']; //get the ID of the record we want to delete from the form
$sqlDel = "DELETE FROM $table WHERE $PK='$selectedID'"; //create the SQL
if (deleteRecord($conn, $sqlDel)) //call the deleteRecord() function
{
echo "<h3>RECORD WITH PK=$selectedID DELETED</h3>";
} else {
echo "<h3 >RECORD WITH PK=$selectedID CANNOT BE DELETED</h3>";
}
//Re-display table with delete options
//Query string
$sqlData = "SELECT * FROM $table"; //get the data from the table
$sqlTitles = "SHOW COLUMNS FROM $table"; //get the table column descriptions
//execute the 2 queries
$rsData = getTableData($conn, $sqlData);
$rsTitles = getTableData($conn, $sqlTitles);
//check the results
$arrayData = checkResultSet($rsData);
$arrayTitles = checkResultSet($rsTitles);
//use resultsets to generate HTML tables with DELETE button
generateDeleteTable($table, $PK, $arrayTitles, $arrayData);
//close the connection
$conn->close();
} else if (isset($_POST['editrecord'])) //if the form has been submitted
{
echo "am in inside";
//DELETE query
$selectedID = $_POST['editrecord']; //get the ID of the record we want to delete from the form
$sqlEDIT = "SELECT FROM $table WHERE $PK='$selectedID'"; //create the SQL
if (deleteRecord($conn, $sqlEDIT)) //call the deleteRecord() function
{
echo "<h3>RECORD WITH PK=$selectedID DELETED</h3>";
} else {
echo "<h3 >RECORD WITH PK=$selectedID CANNOT BE DELETED</h3>";
}
include 'FORMS/newUserForm.html';
$lectFirstName = $_POST[lectFirstName];
$lectLastName = $conn->real_escape_string($_POST['fName']);
$sqlEdit = "UPDATE $table SET FirstName=lectFirstName, LastName=lectLastName WHERE $PK='$selectedID'";
if (deleteRecord($conn, $sqlEDIT)) //call the deleteRecord() function
{
echo "<h3>RECORD WITH PK=$selectedID DELETED</h3>";
} else {
echo "<h3 >RECORD WITH PK=$selectedID CANNOT BE DELETED</h3>";
}
//Re-display table with delete options
//Query string
$sqlData = "SELECT * FROM $table"; //get the data from the table
$sqlTitles = "SHOW COLUMNS FROM $table"; //get the table column descriptions
//execute the 2 queries
$rsData = getTableData($conn, $sqlData);
$rsTitles = getTableData($conn, $sqlTitles);
//check the results
$arrayData = checkResultSet($rsData);
$arrayTitles = checkResultSet($rsTitles);
//use resultsets to generate HTML tables with DELETE button
generateDeleteTable($table, $PK, $arrayTitles, $arrayData);
//close the connection
$conn->close();
} else //this is the first time the form is loaded
{
//display table with delete options
//Query string
$sqlData = "SELECT * FROM $table"; //get the data from the table
$sqlTitles = "SHOW COLUMNS FROM $table"; //get the table column descriptions
//execute the 2 queries
$rsData = getTableData($conn, $sqlData);
$rsTitles = getTableData($conn, $sqlTitles);
//check the results
$arrayData = checkResultSet($rsData);
$arrayTitles = checkResultSet($rsTitles);
//use resultsets to generate HTML tables with DELETE button
generateDeleteTable($table, $PK, $arrayTitles, $arrayData);
//close the connection
$conn->close();
}
echo "</section>";