Help with PHP, $_GET variable

Use a condition to only establish the $result variable if the $_GET['value'] variable exists.

if($_GET['value']){$result=$_GET['value'];}
 
With this i get this error: Undefined variable: _Get
 
Try this:
if(isset($_GET['value'])){$result=$_GET['value'];}

Mind if I ask what version of PHP you're using?
 
With this i get this error: Undefined variable: _Get

Check your syntax. Check everything is there like this "$_GET['value']" without the double quotes of course. If that doesn't help, paste that part of the code here.
 
you can check with isset if a variable is set

So in your example:

Code:
if (isset($_GET['value']))
{
    $result = $_GET['value'];
}
 
The part of code is
if (isset($_Get['page']))
$page = $_GET['page'];
else
$page = 1;

With issest whatever the condition is, the script always executes with else. Even if index.php?page=5 the script will go in else. $page is always 1, with isset.
 
Last edited:
I am using:
Apache Version :2.2.21 PHP Version :5.3.10
 
u can use an alternative to above which will also set a default value (if u havent already previously in ur code):
Code:
$result = ( isset( $_GET['value'] ) ) ? $_GET['value'] : "";
the error u got "Undefined variable: _Get" is cos u forgot the $ sign in the $_GET part ;)
 
sonic1234 said:
With issest whatever the condition is, the script always executes with else. Even if index.php?page=5 the script will go in else.

Thats because $_GET is case sensitive and you wrote
Code:
isset($_Get['page'])
instead of
Code:
isset($_GET['page'])
 
Thanks a lot Mick, this code worked :D

$result = ( isset( $_GET['value'] ) ) ? $_GET['value'] : "";

But can somebody tell me why, if else dint work it was same as the above code:
if (isset($_Get['value']))
$result = $_GET['value'];
else
$result = 1;
 
Oh ok, i get it now, thanks a lot guys for your help and time :) :)
 
Back
Top