Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exit with an error message in PHP/HTML?

I am checking if a particular value is set using isset. I want to exit the script and display an error message like "Name not found, Enter a valid name". Currently I am checking like this:

if ((! isset($_GET["name"])) or (! is_dir($_GET["name"])) or (empty($_GET["name"]))) {

    Print "Name not found, Enter a valid name"
}

After the print, I want to exit without further execution of code. How can I exit with the my error message and no default error message from PHP?

like image 771
brain storm Avatar asked Dec 17 '25 04:12

brain storm


2 Answers

Die or exit: see the php documentation

http://php.net/die

http://php.net/exit

die ("I'm dyin over here");
like image 172
Zak Avatar answered Dec 19 '25 20:12

Zak


 die("Name not found, Enter a valid name");

That should help!

Regards, Felix

like image 43
Felix Lebel Avatar answered Dec 19 '25 21:12

Felix Lebel