I have one form as below in test1.php
<form action="test.php?CID=25" name="form1" METHOD="POST">
<input type=text name="YID" VALUE="22" />
<INPUT TYPE=SUBMIT NAME="SUBMIT" />
</form>
test.php file will request the variable CID and YID.
in classic asp I can request both variable like below.
CID=REQUEST("CID")
YID=REQUEST("YID")
REQUEST will work for both. As CID is a variable which will appear in the hyperlink as below
http://localhost/test.php?CID=25
on submitting the form in test1.php.
in classic asp if any variable is not defined then I can handle the variable as below.
CID=REQUEST("CID"):if isnull(CID) or trim(CID)="" then CID=0
YID=REQUEST("YID"):if isnull(YID) or trim(YID)="" then YID=0
How could it be done in PHP.
For this URL:
http://localhost/test.php?CID=25
If you want the value of CID you would use:
$_GET['CID']
From a POSTed form containing:
<input type=text name="YID" VALUE="22" />
You would use
$_POST['YID']
If you need to test if a veriable is set you can use
$value = isset($_POST['YID']) ? $_POST['YID'] : '';
This is shorthand for
if(isset($_POST['YID'])){
$value = $_POST['YID'];
} else {
$value = 0; // or FALSE or null or '' or any default value you want
}
you can do like this
$_REQUEST['CID']==null ? ($CID=0) : ($CID=$_REQUEST['CID']);
or this can be used-
function getIfSet(&$value, $default = 0)
{
return isset($value) ? $value : $default;
}
$CID = getIfSet($_REQUEST["CID"]);
$CID = (isset($_GET['CID']) and $_GET['CID'] != '') ? $_GET['CID'] : 0;
$YID = (isset($_POST['YID']) and $_POST['YID'] != '') ? $_POST['YID'] : 0;