Page 1 of 1

Set page with URL param

Posted: Thu Nov 17, 2011 11:27 am
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

Re: Set page with URL param

Posted: Thu Nov 17, 2011 10:19 pm
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.

Re: Set page with URL param

Posted: Fri Nov 18, 2011 7:52 am
by lakc
Thank you Jacek.

May I ask why I should nt use die() to send error msgs?

Re: Set page with URL param

Posted: Fri Nov 18, 2011 7:55 am
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.

Re: Set page with URL param

Posted: Fri Nov 18, 2011 7:59 am
by lakc
Thank you Temor for the tip.