I am testing some code to view and delete records from a list if the delete button is clicked. I am getting the following error with the code.
PHP Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home2/tcabsup1/public_html/TeachingPeriod/deleteTeachingPeriod.php on line 5
Table
CREATE TABLE TeachingPeriod (
TPeriodIntake VARCHAR(255),
PRIMARY KEY (TPeriodIntake)
);
deleteTeachingPeriod.php
<?php
include ('db_connect.php');
$TPeriodIntake=$_REQUEST['TPeriodIntake'];
$query = "DELETE FROM TeachingPeriod WHERE TPeriodIntake = '$TPeriodIntake'";
$result = mysqli_query($conn, $query) or die (mysqli_error());
header("Location: viewTeachingPeriod.php");
?>
viewTeachingPeriod.php
<?php
include ('db_connect.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>View Teaching Period</title>
</head>
<body>
<div class="form">
<h2>View Teaching Period</h2>
<table>
<thead>
<tr>
<th><strong>Teaching Period Name</strong></th>
<th><strong>Delete</strong></th>
</tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from TeachingPeriod;";
$result = mysqli_query($conn,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td align="center"><?php echo $row["TPeriodIntake"]; ?></td>
<td align="center">
<a href="deleteTeachingPeriod.php?TPeriodIntake=<?php echo $row["TPeriodIntake"]; ?>">Delete</a>
</td>
</tr>
<?php $count++; } ?>
</tbody>
</table>
</div>
</body>
</html>
It seems a little odd because I can get the code working with the Project table but I cant get it working with the Teaching Period so it doesn't seem like its an issue with the database connection.
All I can imagine is its something to do with how Project has an auto-incrementing interger for a primary key whereas the Teaching period is a natural key with VARCHAR data type.
The only other difference is we only want to be able to delete a teaching period, there should not be an option to edit a teaching period.
The code that DOES work is below. Both reference the same database connection file.
CREATE TABLE Projects (
ProjectID INT(10) AUTO_INCREMENT,
ProjectName VARCHAR(255) NOT NULL,
ProjectDescription VARCHAR(255) NOT NULL,
PRIMARY KEY (ProjectID)
);
<?php
include ('../db_connect.php');
$ProjectID=$_REQUEST['ProjectID'];
$query = "DELETE FROM Projects WHERE ProjectID = $ProjectID";
$result = mysqli_query($conn,$query) or die (mysqli_error());
header("Location: viewProject.php");
?>
<?php
include ('../db_connect.php');
include '../head.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>View Project</title>
</head>
<body>
<div class="form">
<p><a href="registerProject.php">Insert New Project</a>
<h2>View Project</h2>
<table>
<thead>
<tr>
<th><strong>Project Name</strong></th>
<th><strong>Project Description</strong></th>
<th><strong>Edit</strong></th>
<th><strong>Delete</strong></th>
</tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from Projects ORDER BY ProjectName ASC;";
$result = mysqli_query($conn,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td align="center"><?php echo $row["ProjectName"]; ?></td>
<td align="center"><?php echo $row["ProjectDescription"]; ?></td>
<td align="center">
<a href="editProject.php?ProjectID=<?php echo $row["ProjectID"]; ?>">Edit</a>
</td>
<td align="center">
<a href="deleteProject.php?ProjectID=<?php echo $row["ProjectID"]; ?>">Delete</a>
</td>
</tr>
<?php $count++; } ?>
</tbody>
</table>
</div>
<?php include '../footer.php';?>
</body>
</html>
I have been trying to work this out for long enough that am not sure if I am doing something wrong or if I am missing something obvious with the debugging.