Set page with URL param

Ask about a PHP problem here.
Post Reply
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Set page with URL param

Post by lakc »

Hi,

I recently dloaded coding application for a survey.

And I wanted to test the coding for correctness, but have problems in displaying the 1st survey.

Here is the coding:
// This page requires a URL parameter with the QuestionID.
if(isset($_GET["QuestionID"]))
	$Qid = $_GET["QuestionID"];
else
	die("Please set a question id in the URL");

// $QText = $row[1];
The coder has advised, to use this kind of url to call the page:
http://yourserver/survey.php?questionid=1

But i get the error msg "Please set a question id in the URL".? Is it possible to restrict the use of setting a value in the url from the server. The link below is where i found this coding. Is there something that is missing in the code?

http://www.devx.com/webdev/Article/27175/0/page/2
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Set page with URL param

Post by jacek »

$_GET is case sensitive, so

QuestionID is not the same as questionid

Also you should not be using die() to send error messages.
Image
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Re: Set page with URL param

Post by lakc »

Thank you Jacek.

May I ask why I should nt use die() to send error msgs?
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Set page with URL param

Post by Temor »

lakc wrote:Thank you Jacek.

May I ask why I should nt use die() to send error msgs?
Well, it kills the rest of the page ( prevents more code from running ), and that's not usually what you want to do whenever there is an error.

Put the error message in a variable and echo it out somewhere instead :)
Or you could watch some of Jacek's tutorials to see how he handles errors.
lakc
Posts: 32
Joined: Fri Oct 21, 2011 6:05 pm

Re: Set page with URL param

Post by lakc »

Thank you Temor for the tip.
Post Reply