Pass multiple variables by url and read all of them on next page
I have a link pointing to a web page eg. "Land.php". The link looks like this:
<a href="land.php?id=1&cd=a">link</a>
this takes me to land.php page where I can read the first parameter from $id
(and it is 1, right), but I cannot read the second. I have either tried using $cd
or $_GET['cd']
. None of them work.
if i tried isset($cd)
it it says false
. The same goes for isset($_GET['cd'])
.
How do I pass the second parameter (and read it!)?
EDIT:
some code (so people are happy. I guess in this case it's pointless ..).
land.php
<?php
if($_GET['cd']==a)
echo "<h2>HI</h2>";
else
echo "<h2>BY</h2>";
?>
if i use $cd
instead $_GET['cd']
it still doesn't work.
EDIT2 I am not getting any syntax error, it just doesn't behave as expected.
source to share
The value is stored in $_GET['cd']
.
Try to print the array $_GET
withprint_r($_GET);
print_r ($ _ GET) should output
Array
(
[id] => 1
[cd] => a
)
This should be on the page land.php
as get variables are only available on the requested page.
source to share
$_GET['cd']
- correct syntax. You are actually on the page land.php
, i.e. Your browser address bar reads something like
example.com/land.php?id=1&cd=a
Also, it looks like you've included register_globals
if you can read $id
. This is a very bad idea.
Update
The code snippet contains syntax errors. I recommend the following, including including decent bug reporting for development
ini_set('display_errors', 'On');
error_reporting(E_ALL);
if(isset($_GET['cd']) && $_GET['cd'] == 'a') {
echo "<h2>HI</h2>";
} else {
echo "<h2>BY</h2>";
}
source to share