Question

i would like do delete everything on the page and echo just the die()

Example:

Code here!!
<?php $query_area = mysql_query("SELECT * FROM tblcargos WHERE id_tblarea = '$id_tblarea'") or die(mysql_error()); ?>
More code here

So, if the code die, will delete everything after and before die function and echo just the die()

Was it helpful?

Solution

Die() ends the page. That's the whole point of that function :) You don't want to alter that functionality.

A method you cán do (note the end):

$query_area = mysql_query("SELECT * FROM tblcargos") or myCustomFunction();

myCustomFunction() can handle the error any way you like. In fact, I'd strongly recommend doing that in favor of die().
You could make it so it shows a 'nice' error page, explaining the user what just happend.

OTHER TIPS

Here is a very basic example of using output buffering:

ob_start();
// more code here
$query_area = mysql_query("SELECT * FROM tblcargos WHERE id_tblarea = '$id_tblarea'");
if (!query_area) {
     ob_clean();
     die(mysql_error()); 
}
//More code here
ob_end_flush();

This will capture your page's output and display it normally unless you run into an error. Then it will discard the output so far and only output your error message.

Output buffering can get complicated so I would instead recommend restructuring your code so no content is output until after your PHP logic has completed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top