Jump to content
Larry Ullman's Book Forums

Chp 9 - Failed To Open Stream (Classes/html.php)


Recommended Posts

On the Chp 9, CMS site I can't figure out why I'm getting a warning and a fatal error on utilities.inc.php line 4 when I try to add a new page.  Is there a setting in php.ini that needs to be changed or something else that I'm obviously missing? 

 

( ! ) Warning: require(classes/HTML.php): failed to open stream: No such file or directory in C:\wamp\www\ullman_advanced\chp9\includes\utilities.inc.php on line 4

 

( ! ) Fatal error: require(): Failed opening required 'classes/HTML.php' (include_path='.;C:\php\pear;/wamp/bin/php/php5.5.12/pear/') in C:\wamp\www\ullman_advanced\chp9\includes\utilities.inc.php on line 4

 

 

The code for my utilities.inc.php and add_page.php are added below. 

Any assistance will be appreciated.

 

Here is the code for my utilities.inc.php file:

<?php #utilities.inc.php - Script 9.3, see page 294 for explanation.
//Define a function that will autoload the classes:
function class_loader($class){
	require('classes/' . $class . '.php');
	}
	spl_autoload_register('class_loader');

	
//Start the session
session_start();
//Check for a user in the session.
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null;
//Create the database connection as a PDO object.
try {
	$pdo = new PDO('mysql:dbname=cms;host=localhost','root','');
	//Catch any PDO exceptions.
	} catch (PDOException $e){
		$pageTitle = 'Error';
			include('includes/header.inc.php');
			include('views/error.html');
			include('includes/footer.inc.php');
			exit();
			}

Here is the code for my add_page.php:

<?php #Script 9.15, 
//This page both displays and handles the "add a page" form.
require('includes/utilities.inc.php');
//Redirect if the user doesn't have permission.
if(!$user->canCreatePage()){
	header("location:index.php");
	exit();
}
//Create a new form:
set_include_path(get_include_path() . PATH_SEPARATOR . '/wamp/bin/php/php5.5.12/pear/');
require('HTML/QuickForm2.php');


$form = new HTML/QuickForm2('addPageForm');
//Add the title field:
$title = $form->addElement('text','title');
$title->setLabel('Page Title');
$title->addFilter('strip_tags');
$title->addRule('required','Please enter a page title.');
//Add the content field.
$content = $form->addElement('textarea','content');
$content->setLabel('Page Content');
$content->addFilter('trim');
$content->addRule('required','Please enter the page content.');
//Add the submit button.
$submit = $form->addElement('submit', 'submit', array('value'=>'Add This Page'));

//CHECK FOR FORM SUBMISSION AND VALIDATE.
if($_SERVER['REQUEST_METHOD']== 'POST'){
	if($form->validate()){
	//insert the record into db.
	$q = 'INSERT INTO pages (creatorId, title, content, dateAdded) VALUES (:creatorId, :title, :content, NOW()';
	$stmt = $pdo->prepare($q);
	$r = $stmt->execute(array(':creatorId' => $user->getId(), ':title' => $title->getValue(), ':content' => $content->getValue()));

	//If the insert query worked, freeze the form to show the results.
	if($r){
		$form->toggleFrozen(true);
		$form->removechild($submit);
		}
	}
}//End of form submission.

//Create the page.
$pageTitle = 'Add a Page';
include('includes/header.inc.php');
include('views/add_page.html');
include('includes/footer.inc.php');
?>
Link to comment
Share on other sites

Sometimes the best way to fix something is to take a 24 hour break...found the error.

//In add_page.php I changed this:
$form = new HTML/QuickForm2('addPageForm');
//to
$form = new HTML_QuickForm2('addPageForm');
Link to comment
Share on other sites

 Share

×
×
  • Create New...