Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-28-2010, 09:06 AM   #1
Bronze Member
 
Join Date: Feb 2010
Posts: 32
Default Fatal Error in PHP coding

I am encountering an error with the following section of PHP and cannot see the reason. The error is being trapped with the line

Code:
$validator->validateTextOnlyNoSpaces($HTTP_POST_VARS['name'],'section name');
The error message is:
Fatal error: Call to a member function validateTextOnlyNoSpaces() on a non-object in C:\Program Files\xampp\htdocs\newsite2\cmsadmin\newSection.ph p on line 33

Now, this implies that the $HTTP_POST_VARS field of 'name' is not in existence and yet I have declared it clearly within the form at the bottom of the code. The submit is set correctly.

Anyone see what I am missing?

Code:
<?php
	// Call the classes
	require_once('../includes/DbConnector.php');
	require_once('../includes/Validator.php');
	
	// Create instances
	$connector = new DbConnector();
	$theValidator = new Validator();	
	
	// DELETE SECTION ////////////////////////////////////////////////////////////////////
	if  ($HTTP_GET_VARS['action'] == 'delete')
		{
    	// Store the ID of the section to be deleted in a variable
    	$sectionID = $HTTP_GET_VARS['id'];

    	// Validate the section ID, and if it's ok then delete the section
    	if ( $validator->validateNumber($sectionID,'Section ID') )
			{
        	// The validator returned true, so go ahead and delete the section
        	$connector->query('DELETE FROM cmssections WHERE ID = '.$sectionID);
        	echo 'Section Deleted <br><br>';
		    }
		else
			{
        	// The validator returned false, meaning there was a problem
        	echo "Couldn't delete. There was a problem with: ".$validator->listErrors();
    		}
		}
		
	// ADD SECTION ////////////////////////////////////////////////////////////////////
	if ($HTTP_GET_VARS['action'] == 'add')
		{
		$validator->validateTextOnlyNoSpaces($HTTP_POST_VARS['name'],'section name');
		$validator->validateNumber($HTTP_POST_VARS['parent'],'parent section');
	
		if (!$validator->foundErrors())
			{
			$connector->query('INSERT INTO cmssections (name,parentid) VALUES ("'.$HTTP_POST_VARS['name'].'",'.$HTTP_POST_VARS['parent'].')');	
			}
		else
			{
			echo '<b>Please correct '.$validator->listErrors().'</b><br><br>';
			}
		}

	// LIST SECTIONS /////////////////////////////////////////////////////////////////////
	$result = $connector->query('SELECT ID,name,parentid FROM cmssections');

	// Get an array containing the results.
	// Loop for each item in that array
	while ($row = $connector->fetchArray($result))
		{
		echo $row['name'].' - &nbsp;&nbsp; '; // Show the name of section
		echo '<a href="newSection.php?action=delete&id='.$row['ID'].'"> Delete </a>'; // Show the delete link 
		echo '<br>'; // Show a carriage return
		}

?>

	<form name="form1" method="post" action="newSection.php?action=add">
  		<p>Create a Section:</p>
  		<p>&nbsp;Name:
      		<input name="name" type="text" id="name">
  		</p>
  		<p>&nbsp;Parent:
    		<select name="parent">
				<option value="0">None</option>
      			<?PHP
            		// Generate a drop-down list of sections.
					// NOTE : Requires database modifications in article 4
					$result = $connector->query('SELECT ID,name FROM cmssections ORDER BY name');

					// Get an array containing the results.
					// Loop for each item in that array
					while ($row = $connector->fetchArray($result))
						{
						echo '<option value="'.$row['ID'].'">'.$row['name'].'</option>';
						}
			  	?>
    	    </select>
  		</p>
  		<p align="left">
    		<input type="submit" name="Submit" value="Create">
  		</p>
	</form>
gazzieh is offline   Reply With Quote


Old 06-02-2010, 12:37 AM   #2
Silver Member
 
Join Date: May 2010
Posts: 190
Default

Let me know if you solved this because I'm curious as to what the problem was. I couldn't find anything.
__________________
New Jersey Website Design:
We offer services in the following:
Website Design
SEO
Belmar Website Design
New Jersey Web Design
AK Web Design is offline   Reply With Quote
Old 10-11-2010, 06:43 PM   #3
New Member
 
Join Date: Sep 2010
Posts: 7
Default

I should see the Validator.php class code, anyway I believe the problem is here:

you make a new Validator object doing this:

$theValidator = new Validator();

then you call a method (validateTextOnlyNoSpaces) of that class doing this:

$validator->validateTextOnlyNoSpaces($HTTP_POST_VARS['name'],'section name');

but I believe you should call it in $theValidator object, not in $validator, which doesn't exist.

try changing $theValidator = new Validator(); into:

$validator = new Validator();
__________________
Start a logo design contest at Logo Arena! Get your logo designed by top logo designers
logoarena is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:53 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.