Page 2 of 2

Re: Basic code causing errors - but i've no idea why

Posted: Fri Mar 11, 2011 4:34 am
by jim.barrett
Well....as you have them laid out there neither will work...

Re: Basic code causing errors - but i've no idea why

Posted: Fri Mar 11, 2011 4:37 am
by jim.barrett
sorry....

of course you mean to say $_REQUEST['page'] or $_GET['page'] right?

because if you ask for 'test', no such variable is being passed in...and you will get an error.

Re: Basic code causing errors - but i've no idea why

Posted: Fri Mar 11, 2011 5:23 am
by simonmlewis
Ok this is the problem that I have yet to resolve.
In the template I have to ask if there is something in the URL for the variable.
So how do I ask that, and then use the function of getPage or getMenu, without causing the errors? That really is the "money question".

Re: Basic code causing errors - but i've no idea why

Posted: Sat Mar 12, 2011 11:38 am
by califdon
simonmlewis wrote:Thanks for the length explanation, most of which I didn't quite understand.
Are you say that:
$test=$_REQUEST['test'];
.... on it's own, and if the url is, for example: http://www.mytest.com/index.php?page=moon
.... IS going to cause errors in the error log, but...


$test=$_GET['test'];
.... on it's own, and if the url is, for example: http://www.mytest.com/index.php?page=moon
... ISN'T??

If that's the case, it's simple. And what I said about whether my new piece of script is correct...... sounds like it is.
I guess I'm not making myself clear to you. This has nothing to do with the error log. It has to do with programming in PHP and properly using the global variables that store data related to a web page that has been previously sent to a browser. You should read about these variables and try to understand what they are and how they should be used. http://devlog.info/2010/02/04/why-php-r ... dangerous/

Re: Basic code causing errors - but i've no idea why

Posted: Sat Mar 12, 2011 2:43 pm
by simonmlewis
Will do - tho sadly, two pages on, my original question hasn't been answered.
Oh well.

Re: Basic code causing errors - but i've no idea why

Posted: Sat Mar 12, 2011 5:08 pm
by califdon
simonmlewis wrote:Ok this is the problem that I have yet to resolve.
In the template I have to ask if there is something in the URL for the variable.
So how do I ask that, and then use the function of getPage or getMenu, without causing the errors? That really is the "money question".
Sorry, I didn't address that question because, somehow, I didn't see it when I made my previous post.

What I am trying to explain to you is that you'll never be able to write and debug PHP scripts without understanding the basics, like what $_GET, $_POST and $_REQUEST are. They are not simple variables, they are arrays, and they are related to each other due to the fact that $_REQUEST contains all the array elements of both $_GET and $_POST, as well as $_COOKIE. So, usually you could get away with using $_REQUEST without concerning yourself with whether a particular array element came from the URL string ($_GET) or a form element ($_POST), BUT that is very bad practice because some day you may have a script that has a $_POST element and a $_GET element with the same name and you won't know which one you're dealing with! Not to mention the security issue described in the reference I gave you. So, as I said, rather clearly, I thought, in my earlier post, use $_GET. That is what you should always use to get the contents of a parameter that is passed in the URL. Why would you use anything else? Similarly, you should always use $_POST to get the contents of a value that has been entered in an HTML form with the "method='post'" specification.

If you not sure about how an array is different from a variable, again it is vitally important that you acquire this understanding. You cannot successfully write even the simplest of PHP scripts without a firm grasp of fundamentals like that.

I hope that clears this up for you.

Re: Basic code causing errors - but i've no idea why

Posted: Sat Mar 12, 2011 5:16 pm
by simonmlewis
Hi - yes it does.
And I think my solution that I posted (that someone said had too many braces, but then noticed it didn't) is correct.
I have tested this and it appears to be so, as I see no errors on the log anymore related to that.

So the query must first see if there is anything in the URL. And if there is, only THEN run the function getPage. Which is what I think my script now does.

And I agree with you about GET POST and REQUEST. I was just taught to use REQUEST to get info from the URL. And I have to admit, I have countless pages on the web that use it, but will test the theory and at some point, alter them. but there are many!

Re: Basic code causing errors - but i've no idea why

Posted: Sat Mar 12, 2011 8:20 pm
by califdon
I'm afraid you were taught wrong.

Re: Basic code causing errors - but i've no idea why

Posted: Sun Mar 13, 2011 3:47 am
by simonmlewis
That's down to Forums! As I learnt that you can collect the data from the URL, via $_REQUEST.
But you state that to do that, for example to capture that something is completed, this:
index.php?page=edit&c=y
Rather than my using
$c=$_REQUEST['c'];

I should be using:
$c=$_GET['c'];

Correct?

Re: Basic code causing errors - but i've no idea why

Posted: Sun Mar 13, 2011 1:20 pm
by califdon
Yes. Would you please go back and read my previous post, where I boldfaced the pertinent instructions, as well as explained why you can get the same data with $_REQUEST, but should not. I don't know how to say it more emphatically.

Re: Basic code causing errors - but i've no idea why

Posted: Sun Mar 13, 2011 1:24 pm
by simonmlewis
Pertinent?
Emphatically?
Nice big words. But yes, I'll take a look. Thank you. At the time, I was more interested in a 'fix' rather than a lecture about variables. But I see the need to understand.