[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

isset($_GET['var']) not working

Im trying to modify a script from ChartDirector 3.1, the original script created a chart based on a year selected from a user, i wanted to mod this so it would compare two different countrys stats. The problem is when i hit the submit button from select.php the values of the two countrys is not picked up by graph.php. I think i've narrowed it down to the if else statments on graph.php , here--

if (isset($_GET['year'])){
      $SelectedYear = $_GET['year'];
}else{
      $SelectedYear = 2004;
}
if (isset($_GET['country1'])){
      $country1 = $_GET['country1'];
}else{
      $country1 = 'Australia';
}
if (isset($_GET['country2'])){
      $country2 = $_GET['country2'];
}else{
      $country2 = 'Brazil';
}
the first (and original if stat) works fine 'getting' the year selected, but the country1 and 2 vars are not getting set from the form on select.php and thus only comparing info on australia and brazil.
The address bar shows (example) ....select.php?year=1997&country1=Austria&country2=Argentina

echo $_GET["country1"];-- shows nothing on graph.php - but shows correct on select.php
echo $_GET["country2"];-- shows nothing on graph.php - but shows correct on select.php

can any one help.

thank you.
0
drn
Asked:
drn
  • 2
  • 2
  • 2
1 Solution
 
W33BCommented:
How are you submitting your vars to graph.php? sometime I've been tripped up in the past when using a POST method instead of a GET, the following could explain your problem:

<form action="graph.php?year=1975" method="POST">
  <input type="text" name="country1" value="Austria">
  <input type="text" name="country1" value="Argentina">
</form>

this will post and you can access both the $_GET["year"] (in action)
AND
$_POST["country1"], $_POST["country2"]

0
 
drnAuthor Commented:
select.php
-----------------------------------------
<html>
<body>
<form action="<?php echo $HTTP_SERVER_VARS["SCRIPT_NAME"] ?>" method="get">
      <select name="year">
            <option value="1997">1997
            <option value="1998">1998
            <option value="1999">1999
            <option value="2000">2000
            <option value="2001">2001
            <option value="1992">2002
            <option value="1993">2003
            <option value="1994">2004
      </select>
<select name="country1">
      <option value="Argentina">Argentina</option>
      <option value="Armenia; Republic of">Armenia; Republic of</option>
      <option value="Australia" selected>Australia</option>
      <option value="Austria">Austria</option>
      <option value="Azerbaijan; Republic of">Azerbaijan; Republic of</option>
      <option value="Belarus">Belarus</option>
      <option value="Belgium-Luxembourg">Belgium-Luxembourg</option>
      <option value="Belize">Belize</option>
      <option value="Brazil">Brazil</option>
      <option value="Bulgaria">Bulgaria</option>
</select>
VS
<select name="country2">
      <option value="Argentina">Argentina</option>
      <option value="Armenia; Republic of">Armenia; Republic of</option>
      <option value="Australia">Australia</option>
      <option value="Austria">Austria</option>
      <option value="Azerbaijan; Republic of">Azerbaijan; Republic of</option>
      <option value="Belarus">Belarus</option>
      <option value="Belgium-Luxembourg">Belgium-Luxembourg</option>
      <option value="Belize">Belize</option>
      <option value="Brazil" selected>Brazil</option>
      <option value="Bulgaria">Bulgaria</option>
</select>
  <input type="submit" value="submit">
</form>

<?php
if (isset($_GET['year'])){
      $SelectedYear = $_GET['year'];
}else{
      $SelectedYear = 2004;
}
if (isset($_GET['country1'])){
      $country1 = $_GET['country1'];
}else{
      $country1 = 'Australia';
}
if (isset($_GET['country2'])){
      $country2 = $_GET['country2'];
}else{
      $country2 = 'Brazil';
}
?>
<SCRIPT>
      //make sure the select box displays the current selected year.
      document.forms[0].year.selectedIndex = <?=$SelectedYear - 1990?>;
</SCRIPT>

<img src="graph.php?year=<?php echo $SelectedYear ?>">
</body>
</html>
0
 
W33BCommented:
I see where your problem is, you need to change your img src to:

<img src="graph.php?year=<?=($SelectedYear)?>&country1=<?=($country1)?>&country2=<?=($country2)?>">

and btw

<?=($var)?> is the quick way of doing <?php echo $var ?>

and

I don't know how relevant this is to you either but if I'm posting to the same page I set my action to  
<?=($_SERVER["PHP_SELF"])?>

W33B
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rwestonCommented:
If you ever need to see what variables and values are being received, do a:

print_r($_POST);
or
print_r($_GET);
or just
print_r($_REQUEST);

Save yourself some lines of code (terinary operator):
<?
isset($_GET['year']) ? $SelectedYear = $_GET['year'] : $SelectedYear = 2004;
isset($_GET['country1']) ? $country1 = $_GET['country1'] : $country1 = 'Australia';
isset($_GET['country2']) ? $country2 = $_GET['country2'] : $country2 = 'Brazil';
?>

& like W33B Said, action to: <?=$_SERVER["PHP_SELF"]?> but it is == to ="<?=$HTTP_SERVER_VARS["SCRIPT_NAME"] ?>"
0
 
rwestonCommented:
oh eh:

do:

echo("<pre>");
print_r($_POST); // or any other array
echo("</pre>");  // to get a formatted printing of the arrays
0
 
drnAuthor Commented:
It's always something basic hat i miss, lol.
thanks w33b
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now