Jump to content

[SOLVED] PHP - echo issue


petersro

Recommended Posts

While working on the error handler i have an issue with it working but not putting things on a new line, any hints?

// set the error reporting level for this script
error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);

// Change defaults
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');

// set to the user defined error handler
set_error_handler("custom_err_handler");

// The path to the error log file
define('ERROR_LOG_PATH', './logs/error_log.txt');

// Our custom error handler function
function custom_err_handler($num, $str, $file, $line) {
global $error_log_path;
    $err = "";
    $err .= "---- PHP Error ----\n";
    $err .= "Number: [" . $num . "]\n";
    $err .= "String: [" . $str . "]\n";
    $err .= "File: [" . $file . "]\n";
    $err .= "Line: [" . $line . "]\n\n";
    error_log($err, 3, ERROR_LOG_PATH);
    echo $err;
}

 

Link to comment
Share on other sites

i tried the \r\n, it works on the logfile, but doesnt work on the php site, it still displays as normal

 

Logfile output

---- PHP Error ----
Number: [2]
String: [mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'root'@'localhost' (using password: YES)]
File: [C:\wamp\www\onepro\system\sys_mysql.php]
Line: [12]

---- PHP Error ----
Number: [1024]
String: [256]
File: [C:\wamp\www\onepro\system\sys_mysql.php]
Line: [12]

---- PHP Error ----
Number: [8]
String: [use of undefined constant db_name - assumed 'db_name']
File: [C:\wamp\www\onepro\system\sys_mysql.php]
Line: [13]

---- PHP Error ----
Number: [2]
String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource]
File: [C:\wamp\www\onepro\system\sys_mysql.php]
Line: [13]

---- PHP Error ----
Number: [1024]
String: [256]
File: [C:\wamp\www\onepro\system\sys_mysql.php]
Line: [13]

 

Website display

---- PHP Error ---- Number: [2] String: [mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES)] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [8] String: [use of undefined constant db_name - assumed 'db_name'] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [2] String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] 

Link to comment
Share on other sites

thanks mate working on introducing it in my code, i have another question, would make things more cleaner, is there a way i can when

$db = mysql_select_db(db_name,$conn) or trigger_error(E_USER_ERROR);

trigger_error(E_USER_ERROR) is reached,

 

Is there a way to if there is a problem throw a custom error, secondly is there a way to get it to re-direct on error to say error.php on the root of the site, displaying the echo of whats wrong, in a clean html layout. im guessing the first is possable with a varable, but i dont know how to do the second part.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.