Forum Moderators: coopster

Message Too Old, No Replies

Aborting PHP script

         

ffoeg

3:07 pm on May 25, 2006 (gmt 0)

10+ Year Member



I know that when using PHP to connect to MySQL databases, it is sometimes useful to use the
die()

command.

What I have noticed is that this command seems to stop both the PHP and remaining HMTL script from being processed.

My question is, is there any way of stopping the script from executing, but leaving the regular HTML to carry on executing?

jatar_k

3:31 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you need to handle an error as opposed to just using die. You test the return from the function and do something else if the query doesn't work

there is an example here
[php.net...]

<?php 
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>

you don't to use die inside the if and possibly could do your real processing in the if and have an else that handles the invalid query, maybe something like

<?php 
$result = mysql_query('SELECT * WHERE 1=1');
if ($result) {
// continue processing
} else {
// show some default html
}
?>

something like that would work

ffoeg

7:40 pm on May 25, 2006 (gmt 0)

10+ Year Member



Aah. I see. Thanks.

So its not really a question of whether there is a specific command to handle errors, its just about how you handle them.

jatar_k

7:59 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> how you handle them

exactly