I am trying to pass a variable to PHP page using URL GET but I get blank space, what is wrong?!
url: http://localhost:2651/index_main.php?teamName=Liverpool
here is the destination PHP file:
<?php
$teamName = $_GET['teamName'];
?>
<html>
<body>
<?php
$searchQuery = $api->searchTeam(urlencode('<?php $_GET["teamName"]; ?>')) // here must get the team name from previous page
?>
<h3>All home matches of <?php echo $team->_payload->name; ?>:</h3>
</body>
</html>
First, your code is not clean, you use too many php tags. Here is your code now :
<html>
<head>
</head>
<body>
<?php
$teamName = $_GET['teamName'];
$searchQuery = $api->searchTeam(urlencode($teamName)); // here must get the team name from previous page
?>
<h3>All home matches of <?php echo $team->_payload->name; ?>:</h3>
</body>
</html>
Second, in your urlencode
, you put additional php tags and you didn't use the variable you just set before.