|
|
#1 |
|
Bronze Member
![]() Join Date: Feb 2010
Posts: 32
|
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'); 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'].' - '; // 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> Name:
<input name="name" type="text" id="name">
</p>
<p> 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>
|
|
|
|
|
|
#2 |
|
Silver Member
![]() Join Date: May 2010
Posts: 190
|
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 |
|
|
|
|
|
#3 |
|
New Member
![]() Join Date: Sep 2010
Posts: 7
|
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|