Discussion
I have a page - call it index.php
The first visit to the page, the URL is /website/index.php
There is a link on index.php, which links to index.php passing a parameter, p.
That is, it links to /website/index.php?p=1 for example.
Now in the code of index.php, I do this:
if ($_REQUEST['p'])
{
....
This is fine when the parameter is on the URL, but gives an unknown index error when just visiting index.php.
How does one go about reloading a page and check whether something has been submitted for example without getting this error?
Cheers!
The first visit to the page, the URL is /website/index.php
There is a link on index.php, which links to index.php passing a parameter, p.
That is, it links to /website/index.php?p=1 for example.
Now in the code of index.php, I do this:
if ($_REQUEST['p'])
{
....
This is fine when the parameter is on the URL, but gives an unknown index error when just visiting index.php.
How does one go about reloading a page and check whether something has been submitted for example without getting this error?
Cheers!
_dobbo_ said:
ok, php isn't my thing, but wouldn't you just use the "else" statement to catch anything that doesn't match your if statement?
Or failing that, (and I'm guessing the syntax for php)
elseif ($_REQUEST[''])
{
Doesn't work like that unfortunately.
If I have:
if ($_REQUEST['p'])
{
Do something;
}
else
{
Do something else;
}
...it still throws an error about "Unknown index p" if the page is loaded without the parameter.
if (isSet( $_GET['p'] ) )
{
}
else
{
}
Get is used to pull parameters from the url string array (i.e. index.php?p=george), _POST is used to pull from the form post array. isset simply checks to see if something is equal to p and returns a boolean (true / false).
REmember you can use if statements with html:
<?PHP
if(...)
?>
some html
<?
}
else
{
?>
some more html.
<?
}
>> Edited by docevi1 on Thursday 3rd November 20:16
{
}
else
{
}
Get is used to pull parameters from the url string array (i.e. index.php?p=george), _POST is used to pull from the form post array. isset simply checks to see if something is equal to p and returns a boolean (true / false).
REmember you can use if statements with html:
<?PHP
if(...)
?>
some html
<?
}
else
{
?>
some more html.
<?
}
>> Edited by docevi1 on Thursday 3rd November 20:16
docevi1 said:
if (isSet( $_GET['p'] ) )
{
}
else
{
}
Get is used to pull parameters from the url string array (i.e. index.php?p=george), _POST is used to pull from the form post array. isset simply checks to see if something is equal to p and returns a boolean (true / false).
REmember you can use if statements with html:
<?PHP
if(...)
?>
some html
<?
}
else
{
?>
some more html.
<?
}
>> Edited by docevi1 on Thursday 3rd November 20:16
Brilliant, I will try that thanks.
I'm always confused between GET, POST and REQUEST.
So:
GET: Get parameters from URL
POST: Get form values from form submission
REQUEST: ?
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


