3

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?

3 Answers 3

3

Die or exit: see the php documentation

http://php.net/die

http://php.net/exit

die ("I'm dyin over here");
Sign up to request clarification or add additional context in comments.

1 Comment

please see my comments below and if you could provide solution, it will be great. Thanks!
1
 die("Name not found, Enter a valid name");

That should help!

Regards, Felix

2 Comments

But this did not display the text in browser. when I looked as page source, I could see the message. how can I have it display in the broswer where the URL is run
@user1988876 this piece of code is supposed to show Name not found, Enter a valid name in the browser.
1

You would use the die or exit methods. This will halt all PHP and HTML from being displayed or executed.

Example:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.