Reputation: 334
I have a link that points to a webpage e.g. "land.php". The link looks like this:
<a href="land.php?id=1&cd=a">link</a>
this takes me to the page land.php where I can read the first parametere with $id
(and it is equal to 1, correctly), but I cannot read the second one. I either tried with $cd
or $_GET['cd']
. None of them works.
if I tried isset($cd)
it says false
. Same thing for isset($_GET['cd'])
.
How can I pass the second parameter too (and read it!)?
EDIT:
some code (so people are happy. I think it's pointless in this case..).
land.php
<?php
if($_GET['cd']==a)
echo "<h2>HI</h2>";
else
echo "<h2>BY</h2>";
?>
if I use $cd
instead of $_GET['cd']
it doesn't work anyway..
EDIT2 I don't get any syntax error, it just doesn't behave how expected.
Upvotes: 3
Views: 24598
Reputation: 164731
$_GET['cd']
is the correct syntax. Are you actually on the land.php
page, ie does your browser's address bar read something like
example.com/land.php?id=1&cd=a
Also, it looks like you have register_globals
enabled if you can read $id
. This is a very bad idea.
Your code snippet contains syntax errors. I recommend the following, including enabling decent error 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>";
}
Upvotes: 0
Reputation: 5204
The value is stored in $_GET['cd']
.
Try printing out the $_GET
array, with print_r($_GET);
print_r($_GET) should output
Array
(
[id] => 1
[cd] => a
)
This should ofcourse be in the land.php
page, as the get variables are only available in the requested page.
Upvotes: 1
Reputation: 2325
Your server might be set up to accept semicolon instead of ampersands. Try replacing & with ;
Upvotes: 0