dcrudo
asked on
$_POST $_GET Question in PHP ...
Dear All,
I have the following:
if($_GET['cmd'] == "")
{
if($_POST['cmd'] == $nil)
{
$cmd = "";
}
else
{
$cmd = $_POST['cmd'];
}
}
else
{
$cmd = $_GET['cmd'];
}
Basically I would like to be able to pass variables either with post (from a form) or with get (from a string in the url) to a PHP script.
The problem is that using the condition above, if for instante the $_POST variable is empty ...the scripts gives an error like:
"Undefined index: cmd in /var/www/vhosts/demo.shiro neko.com/h ttpdocs/cf /commands. php on line 21"
Is there a way to tell PHP that if the variable is not there...just ignore it?
Thank you!
Dave.
I have the following:
if($_GET['cmd'] == "")
{
if($_POST['cmd'] == $nil)
{
$cmd = "";
}
else
{
$cmd = $_POST['cmd'];
}
}
else
{
$cmd = $_GET['cmd'];
}
Basically I would like to be able to pass variables either with post (from a form) or with get (from a string in the url) to a PHP script.
The problem is that using the condition above, if for instante the $_POST variable is empty ...the scripts gives an error like:
"Undefined index: cmd in /var/www/vhosts/demo.shiro
Is there a way to tell PHP that if the variable is not there...just ignore it?
Thank you!
Dave.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I will split the points because more than one solution was good! Actually I've used parts of all of them ;
Thx again!
Dave
I will split the points because more than one solution was good! Actually I've used parts of all of them ;
Thx again!
Dave
You can also just use the $_REQUEST array instead of the complicated if structure:
$cmd = $_REQUEST['cmd'];
-r-