Help with include file syntax for beginner

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, :blush:, 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. :slight_smile:

~Jason

How can I get it to wait for a user response

Noway.
You can get it only with another call to your script.
PHP scripts don’t “run” continuosly. The nature of web-application is discrete. PHP send HTML to the browser and die. User click a link, browser request a PHP script, PHP send HTML to the browser and so on.

So, when you see HTML in your browser, PHP already dead.
You can’t use include for the confirmation page. Another page with post form must be used
or simple javascript on the same page as an option. But I’d suggest to use PHP in order to learn it deeper

Thank you for responding Shrapnel_N5.

I guess my thick head is thinking that the include IS giving me another page with a post form - called from my index file.

So, when you see HTML in your browser, PHP already dead.

Does this mean that the browser runs through (executed vs. parsed) the whole index.php, including the ‘includes’, before anything is displayed? (As my index is one php<>)

~Jason

Slightly different.
Browser don’t run PHP. It is PHP interpreter on the server side, who run through the whole index.php, including the ‘includes’, giving out clean HTML. You can use your browser View source feature to be convinced.
But result the same: php script got executed before anything is displayed

include does exactly the same as if you copy included script contents and paste it in place of include operator.

Read the first couple pages

Thanks crmalibu. Even though I was aware that php is server side, I’m as green as they come. Thanks for everyone’s help. It was the browser comment wasn’t it? Dang fingers. :blush: I’ll figure out a solution as I learn.

btw. I posted for opinions about schooling if anyone wants to vent.

http://www.sitepoint.com/forums/showthread.php?t=663582

Success. My first php molehill climbed. Thanks again for all the responses.