Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fatal Error in PHP coding
10-27-2010, 07:18 PM
Post: #1
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?

<?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>

Web Design Directory | Web Designers | SEO Melbourne
Find all posts by this user
Quote this message in a reply
12-13-2010, 05:19 PM
Post: #2
RE: Fatal Error in PHP coding
To solve this problem you can consult any php developer. Here you find the solution of this problem.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-04-2011, 03:59 PM
Post: #3
RE: Fatal Error in PHP coding
set_error_handler

(PHP 4 >= 4.0.1, PHP 5)

set_error_handler — Sets a user-defined error handler function
Report a bug
Description
mixed set_error_handler ( callback $error_handler [, int $error_types = E_ALL | E_STRICT ] )

Sets a user function (error_handler) to handle errors in a script.

This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions (using trigger_error()).

It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.

Also note that it is your responsibility to die() if necessary. If the error-handler function returns, script execution will continue with the next statement after the one that caused an error.

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time.
Report a bug
Parameters

error_handler

The user function needs to accept two parameters: the error code, and a string describing the error. Then there are three optional parameters that may be supplied: the filename in which the error occurred, the line number in which the error occurred, and the context in which the error occurred (an array that points to the active symbol table at the point the error occurred). The function can be shown as:

handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )

errno
The first parameter, errno, contains the level of the error raised, as an integer.
errstr
The second parameter, errstr, contains the error message, as a string.
errfile
The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string.
errline
The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer.
errcontext
The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context.

If the function returns FALSE then the normal error handler continues.
error_types

Can be used to mask the triggering of the error_handler function just like the error_reporting ini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reporting setting.

Report a bug
Return Values

Returns a string containing the previously defined error handler (if any). If the built-in error handler is used NULL is returned. NULL is also returned in case of an error such as an invalid callback. If the previous error handler was a class method, this function will return an indexed array with the class and the method name.

Web Designers Directory | Advertise Web Design Business | Website Design
Find all posts by this user
Quote this message in a reply
10-28-2011, 05:08 PM
Post: #4
RE: Fatal Error in PHP coding
These are the three fatal errors in php coding
1.Call to undefined function
2.Parse error
3.SQL query errors

Web Hosting Companies in Bangalore | Top Web Design Companies in India | Best Websites Design || Make Any Site
Find all posts by this user
Quote this message in a reply
09-06-2012, 12:08 AM
Post: #5
RE: Fatal Error in PHP coding
thanks for this valuable stuff here good share

android update| iphone updates| samsung android phones|
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)