title: storing the selected value from drop down list to a variable in php
body: <p>I have populated a drop down list using values from a database in my web page. I use <strong>MySQL</strong> database and <strong>PHP</strong> for coding and <strong>HTML</strong> for design. Now, if I select a value from the drop down list and submit it, I want the selected value to be stored in a new variable. I will transfer the variable again to a new web page. 
  I tried to do this using the <strong>$_GET</strong> and <strong>$_REQUEST</strong> codes, but none of them work. Please suggest me the solutions.</p>
  
  <p>Here is the code:</p>
  
  <p>PHP and HTML code for Drop Down List:</p>
  
  <pre><code>&lt;?php
  $yearval=$_GET['year'];
  $classval=$_GET['class'];
  $semesterval=$_GET['semester'];
  mysql_connect("localhost","root",""); // (host, username, password)
  mysql_select_db("digint") or die("Unable to select database"); //select db
  ?&gt;
  &lt;table width="500" border="1" align="center" cellpadding="0" cellspacing="1"&gt;
  &lt;tr&gt;
  &lt;td&gt;SELECT YOUR SUBJECT AND ENTER THE SUBJECT ACCESS CODE&lt;/td&gt;
  &lt;table width="400" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"&gt;
  &lt;form method="post" action="accesscheck.php"&gt;
  &lt;tr&gt;
  &lt;td&gt;Select Subject&lt;/td&gt;
  &lt;td&gt;
  &lt;?php
  //Subject selection
  $result = mysql_query("select DISTINCT subject from accessindex where semester=$semesterval");
  echo '&lt;select id="subject" name="subject"&gt;&lt;OPTION&gt;';
  echo "Select a subject&lt;/OPTION&gt;";
  while ($row = mysql_fetch_array($result)){
  $subject = $row["subject"];
  echo "&lt;OPTION value=\"$subject\"&gt;$subject&lt;/OPTION&gt;";
  }
  echo '&lt;/SELECT&gt;';
  ?&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="78"&gt;AccessKey&lt;/td&gt;
  &lt;td width="294"&gt;&lt;input name="myaccesskey" type="password" id="myaccesskey"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;td&gt;
  &lt;input type="submit" name="AccessCheck" value="Submit"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP code for using the selected value:</p>
  
  <pre><code>&lt;?php
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  $myaccesskey=$_POST['myaccesskey']; 
  $subjectval=$_POST['subject'];
  
  $myaccesskey = stripslashes($myaccesskey);
  $myaccesskey = mysql_real_escape_string($myaccesskey);
  $subjectval = stripslashes($subjectval);
  $subjectval = mysql_real_escape_string($subjectval);
  $sql="SELECT accesskey FROM accessindex WHERE accesskey='$myaccesskey' and subject=$subjectval";
  $result=mysql_query($sql);
  $count=mysql_num_rows($result);
  if($count==1){
  header("location:marksentry.php");
  }
  else {
  echo "Wrong Subject Access Key";
  }
  </code></pre>