How to stop the script after an error

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
Joan Garnet
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Mon Dec 23, 2002 5:29 am

You can use this exit()

Code: Select all

$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
    or exit("unable to open file ($filename)");

or you can use trigger_error() -->

Code: Select all

mysql_connect("localhost", "user", "database", "pass") or trigger_error("Could not connect to MySQL database", E_USER_ERROR);

or you can use die() -->

Code: Select all

mysql_connect("localhost", "user", "database", "pass")or die("Connect Error: ".mysql_error());

When you use die() after an open <html> tag, don't forget to use die like this : die("blabla\n\n</body>\n\n</html>") ; This will close the body and html tags.


Post Reply