Code: Select all
function manage() {
global $connection;
$manage = "SELECT * FROM subject ORDER BY id ASC";
$table = mysql_query($manage, $connection) or die ("Database course query failed: " . mysql_error());
$num = mysql_num_rows($table);
$i = 0;
while ($i < $num) {
$row = mysql_fetch_array($table);
$cid = $row['id'];
$cname = $row['name'];
echo '<form action="man.php" method = "post"><input type="hidden" name="id" value="'.$row['id'].'"/><input type="hidden" name="name" value="'.$row['name'].'"/></td>';
echo '<tr>';
echo"<td width = '40%'>" .$row['id']. " - " . $row['name']."</td>";
echo "<td align = 'center'><input type = 'submit' value = 'Delete'</type>";
echo "<td align = 'center'><input type = 'submit' value = 'Edit'</type></td>";
echo '</tr></form>';
$i++;
}
if (isset($_POST['id'])) {
$qry = "DELETE FROM subject WHERE id = $_POST[id]";
$result = mysql_query($qry, $connection) or die ("Database course delete query failed: " . mysql_error());
$increment = "ALTER TABLE course AUTO_INCREMENT = 1";
$inc_reset = mysql_query($increment,$connection) or die ("Could not reset auto increment: " . mysql_error());
header("location:man.php");
}
if (isset($_POST['name'])){
header("location:index.php");
}
}
Thanks