Hi. I’m going through Kevin Yank’s book Build Your Own Database Driven Web Site Using PHP & MySQL(Chapter 7) and am trying to fulfill one of his side challenges.
It should be relatively easy, , but I believe I am not understanding something fundamental here.
My objective is this: When a user pushes a delete button(input in a form) the controller script opens a confirmation page via an include.
Problem: After loading include the controller script does not ‘pause and wait’ but keeps on chugging. How can I get it to wait for a user response from the ‘confirm’ script?
if (isset($_POST[‘action’]) and $_POST[‘action’] == ‘Delete’)
{
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/confirm.inc.php’;// Do they really want to delete?
echo "Oh man.";//reaches this visual response before user input in include
if (isset($_POST['check']) and isset($_POST['check']) == 'yes')
{
echo "Here I am!";//visual to see if we get into if - doesn't happen
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; //connect to database
$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'; //display error form
exit();
}
//header('Location: .'); Not sure if this is needed
//exit();
}
// Continues down controller script giving warnings
Here is the ‘confirm’ script:
<?php include_once $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/helpers.inc.php’; ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>Confirm</title>
<meta http-equiv=“content-type”
content=“text/html; charset=utf-8”/>
</head>
<body>
<p>Are you sure you want to do that?</p>
<form action=“<?php echo $_SERVER[‘PHP_SELF’]; ?>”" method=“post”>
<blockquote>
<p>
<input type=“submit” name=“check” value=“yes”>
<input type=“submit” name=“check” value=“no”>
</p>
</blockquote>
</form>
</body>
</html>
I realize this is fundamental -I’ve put in 3 hours trying to fix it so I’m missing it. Thanks.
~Jason