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
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Mon Dec 23, 2002 5:29 am

You can use this exit()

Code: Select all

<?php
$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());

Importatnt!
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.

bye
:D

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 1 guest