Is it possible to retrieve the number that the error line of code is on?

Closest I have come to is mysql_error() but that does not tell me the correct number the line of code is on just like line 1 and it isnt?

Line of Code: In your text editor everyline is coded from 1,2,3,etc

Thanks, Regards X

If you use die function and if an error occurs and prints the die message, then its pretty obvious where exactly the error has occurred !
For runtime errors, php parser will only let you know where the error has occurred if you have error_reporting turned on.

Ya I was using the die function but it was causing me problems but if you have multiple die statements then :p, which you would have seen in the previous threads.

My error reporting is as follows, after reading the comments it seems this is the best anyways "error_reporting = E_ALL & ~E_NOTICE"

Ya I was using the die function but it was causing me problems but if you have multiple die statements then :p, which you would have seen in the previous threads.

;) Then, you will fix the errors one by one !

My error reporting is as follows, after reading the comments it seems this is the best anyways "error_reporting = E_ALL & ~E_NOTICE"

Yep! In my opinion, that is the best option of error reporting. :)

If you are talking about the line number the die() function is used on then the following is an alternative die function that will show the line number.

function dieline($stringz) {
$dataz=file_get_contents(basename($_SERVER['PHP_SELF']));
$datazz=explode($stringz,$dataz);
$rowz=substr_count($datazz[0], '
'); //must start at beginning of line
die ('<b>Error Line number '.$rowz.'</b><br>'.$stringz);
}
//now to use it
$result=mysql_query('SELEC * FROM `table`') or dieline('Error 001'.mysql_error());

The only thing to keep in mind is that the string you enter into the die function needs to be unique from all the other strings in the file. So the best way to avoid the wrong line number from comming up is having the phrase 'Error 001' before the mysql error reporting except replace the number with a unique number from all the other die() / dieline() functions.

If you are talking about the line number the die() function is used on then the following is an alternative die function that will show the line number.

function dieline($stringz) {
$dataz=file_get_contents(basename($_SERVER['PHP_SELF']));
$datazz=explode($stringz,$dataz);
$rowz=substr_count($datazz[0], '
'); //must start at beginning of line
die ('<b>Error Line number '.$rowz.'</b><br>'.$stringz);
}
//now to use it
$result=mysql_query('SELEC * FROM `table`') or dieline('Error 001'.mysql_error());

The only thing to keep in mind is that the string you enter into the die function needs to be unique from all the other strings in the file. So the best way to avoid the wrong line number from comming up is having the phrase 'Error 001' before the mysql error reporting except replace the number with a unique number from all the other die() / dieline() functions.

Hi Cwarn...
Can u explain me what is basename...

file_get_contents([B]basename[/B]($_SERVER['PHP_SELF']));

basename is the filename within the path inputed. So say the filename was located /folder1/folder2/folder3/index.php basename would convert it to index.php

basename is the filename within the path inputed. So say the filename was located /folder1/folder2/folder3/index.php basename would convert it to index.php

Hi Thank u Cwarn....
oooh..its nice...i was struggling many times.... how can i get only filename....now i got it...

Thank u..

This article has been dead for over six months. Start a new discussion instead.