Did anyone ever solve this?
[QUOTE=Caffeinerush;4469391]Hi, I’m up to the point that challenges to confirm deleting a user from the database instead of 1 click deleting.
So far the ID of the user to delete is being picked up by a hidden form field in the template, but when I click the “yes” button, the form value doesn’t seem to submit, so the delete (if statement) doesn’t run.
Here’s the delete code from the controller (index.php):
// confirm deletion
if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include $_SERVER['DOCUMENT_ROOT'] . '/phpmysql_book/includes/db.inc.php';
$id = mysqli_real_escape_string($link, $_POST['id']);
include 'confirm.html.php';
exit();
}
// delete author, and their jokes
if (isset($_POST['authorid']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/phpmysql_book/includes/db.inc.php';
//$id = mysqli_real_escape_string($link, $_POST['id']);
// Get jokes belonging to author
$sql = "SELECT id FROM joke WHERE authorid='$id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Error getting list of jokes to delete.';
include 'error.html.php';
exit();
}
// For each joke
while ($row = mysqli_fetch_array($result))
{
$jokeId = $row[0];
// Delete joke category entries
$sql = "DELETE FROM jokecategory WHERE jokeid='$jokeid'";
if (!mysqli_query($link, $sql))
{
$error = 'Error deleting category entries for joke.';
include 'error.html.php';
exit();
}
}
// Delete jokes belonging to author
$sql = "DELETE FROM joke WHERE authorid='$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Error deleting jokes for author.';
include 'error.html.php';
exit();
}
// Delete the author
$sql = "DELETE FROM author WHERE id='$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Error deleting author.';
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}
This is the confirm template(confirm.html.php):
...
<h1>Delete Author Confirmation</h1>
<p>Are You sure you want to delete the author? This action is permanent.</p>
<form action="?" method="post">
<p>
<input type="hidden" name="authorid" value="<?php echo $id; ?>"/>
<input type="submit" value="Yes"/>
</p>
</form>
</body>
</html>
Thanks.[/QUOTE]