title: Showing Selection from Mysql populated Dropdown Select Form
body: <p>Stumped programming newbie here.</p>
  
  <p>I started learning Php a couple of months ago (with a little HTML).</p>
  
  <p>Been trying to create a dropdown select form populated from Mysql. As you will see from my code below, I think I've achieved that (please let me know if you notice any "mistakes" in the code).</p>
  
  <p>My problem is showing/echoing the selected option/value. No matter what I select and submit from the dropdown list, only the first item shows (in this case: Alabama -- with stateid 1).</p>
  
  <p>I've tried all sorts of stuff that I've seen online but nothing seems to work.</p>
  
  <p>There are a lot of suggestions that invoke javascript, but like I said, I am totally new to programming, so-- one language at a time. I'd like to get a good grasp of php before jumping to other languages.</p>
  
  <p>Surely this can be solved with just php, correct?</p>
  
  <p>By the way, the ultimate goal is to create a multiple --about 3 or four-- progressive dropdown forms (State, County, City). So, if you would be so kind as to indulge me, I'd also like to learn how to pass the selected value (e.g. State) to the next query/dropdown.</p>
  
  <p>I'm ok with a bunch of dropdowns with submit buttons for now. I'll eventually learn javascript.</p>
  
  <p>But trying to figure out how to show the selected State is driving me nuts.</p>
  
  <p>Your help/information is greatly appreciated.</p>
  
  <p>"STATES" TABLE</p>
  
  <pre><code>CREATE TABLE States (
  stateid int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  state_name varchar(25) NOT NULL
  )
  ENGINE=INNODB,
  DEFAULT CHARACTER SET utf8;
  </code></pre>
  
  <p>SELECT/OPTION POPULATED FROM DATABSE -- "pick_state.php":</p>
  
  <pre><code>$con = mysql_connect("localhost", "testx", "testx") or die('Could not connect to server');
  mysql_select_db("US", $con) or die('Could not connect to database');
  
  $stateid = $_GET['stateid'];
  $state_name = $GET['state_name'];
  
  $query = "SELECT stateid,state_name FROM States";
  
  $result = mysql_query($query) or die(mysql_error());
  
  
  $row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error());
  
  
  $stateid = $row['stateid'];
  $state_name = $row['state_name'];
  
  echo "Chosen state is: $state_name"; 
  </code></pre>
  
  <p>PROCESSING FILE -- "show_state.php" :</p>
  
  <pre><code>&lt;?php
  
  $con = mysql_connect("localhost", "test", "test") or die('Could not connect to server');
  mysql_select_db("US", $con) or die('Could not connect to database');
  
  echo "&lt;form action=\"show_state.php\" method=\"get\"&gt;\n";
  
  echo "&lt;select name=\"state_name\"&gt;\n";
  
  $query="SELECT stateid,state_name FROM States";
  
  // ALSO : $query = "SELECT * FROM States "; --Does not work either//
  
  $result=mysql_query($query);
  
        while($row=mysql_fetch_array($result,MYSQL_ASSOC))
  
        {
            $stateid = $row['stateid'];
            $state_name= $row['state_name'];
            echo "&lt;option value=\"$stateid\"&gt;$state_name&lt;/option&gt;";
        }
  
        echo "&lt;/select&gt;\n";
        echo "&lt;input name=\"submit\" type=\"submit\" id=\"stateid\" value=\"submit\" /&gt;\n";
        echo "&lt;/form&gt; \n";
  
   ?&gt;
  </code></pre>
  
  <p>No matter what I chose and submit, the following page always show only the FIRST item on the table: Alabama</p>
  
  <p>PAGE SHOWS: "Chosen state is: Alabama"</p>
  
  <p>URL When I select and submit ARKANSAS:</p>
  
  <p>/show_state.php?state_name=4&amp;submit=submit</p>
  
  <p>Does this mean that it is retrieving the correct, selected/submitted stateid (in this case: 4 --Arkansas' stated) but just not "echoing" the state name?</p>
  
  <p>TRIED the following on show_state.php</p>
  
  <pre><code>$query = "SELECT stateid,state_name FROM States WHERE state_name = $state_name";
  </code></pre>
  
  <p>PAGE SHOWS: Blank</p>
  
  <pre><code>$query = "SELECT stateid,state_name FROM States WHERE stateid= $stateid";
  </code></pre>
  
  <p>PAGE SHOWS:  "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"</p>
  
  <pre><code>if(isset($makeid))
  </code></pre>
  
  <p>PAGE SHOWS: <code>"Query was empty"</code></p>
  
  <pre><code>if(isset ($_GET['makeid']))
  </code></pre>
  
  <p>PAGE SHOWS: <code>"Your Car is a      "</code></p>