html - How to see which option in Pull-Down Menu is selected in PHP? -


i've been stuck on assignment. in assignment have use pull-down menu change displayed database. so, example if option selected courses , grades shown.if on other hand option b selected on database shown. though if name options <option value = "1" name = "reg" >student registration</option> use if (isset($_post['reg'])) work , i'm thinking maybe not correct way solve issue. i'll include snippet of html code has menu , full php code.

<?php  include("account.php");  //connect mysql database  session_start();  $dbc = mysqli_connect($hostname, $username, $password, $database) or die("unable connect mysql database");  echo "connected mysql<br>";  $user = $_post['name'];  $num = $_post['number'];  if(isset($_post['submit']))  {      if (empty ($user))       {          echo "you must enter unique username <br />";      }      if (empty ($num))       {          echo "you must enter id <br />";      }       	$query = "select * studentdb studentname = '". mysqli_real_escape_string($dbc,$user) ."' , studentid = '". mysqli_real_escape_string($dbc,$num) ."'" ;  	$result = mysqli_query($dbc,$query);  	if (mysqli_num_rows($result) == 1)   	{         if (isset($_post['reg']))  	   {  		   echo 'student name: ' . $row['student name'] . '| student e-mail: ' . $row['e-mail'] .';'. '| student id: ' . $row['student id'] . '| student courses: ' . $row['student courses'] .'| student transcript: ' . $row['student transcript'] .'<br />';  	   }  	   if (isset($_post['tran']))  	   {  		   echo 'student name: ' . $row['student name'] . '| student e-mail: ' . $row['e-mail'] .';'. '| student id: ' . $row['student id'] . '| student courses: ' . $row['student courses'] .'| student transcript: ' . $row['student transcript'] .'<br />';  	   }  	}  	else  	{  		echo"unsuccessful login";  	}  session_destroy();  }  else  {  		echo "empty";  }  ?>
<td>  	<select id = "mylist">      <option value = "1" name = "reg" >student registration</option>  	  <option value = "2" name = "tran" >student transcript</option>    </select>  </td>

if full html code need , ask , i'll add it. so, summarize question asked : is there way use if (isset($_post[]))to check option on pull-down menu selected , if not other method can use that?

thank you

edit:

i changed html , php code :

<?php  include("account.php");  //connect mysql database  session_start();  $dbc = mysqli_connect($hostname, $username, $password, $database) or die("unable connect mysql database");  echo "connected mysql<br>";  $user = $_post['name'];  $num = $_post['number'];  if(isset($_post['submit']))  {      if (empty ($user))       {          echo "you must enter unique username <br />";      }      if (empty ($num))       {          echo "you must enter id <br />";      }       	$query = "select * studentdb studentname = '". mysqli_real_escape_string($dbc,$user) ."' , studentid = '". mysqli_real_escape_string($dbc,$num) ."'" ;  	$result = mysqli_query($dbc,$query);  	if (mysqli_num_rows($result) == 1)   	{         if (isset($_post['list'] == '1'))  	   {  	   }  	   if (isset($_post['list'] == '2'))  	   {  	   }   	}  	else  	{  		echo"unsuccessful login";  	}  session_destroy();  }  else  {  		echo "empty";  }  ?>
 <td>   <select id = "mylist" name = "list" >     <option value = "1" >student registration</option>  	 <option value = "2" >student transcript</option>   </select>  </td>
causes crash when click submit. when change php code this:

<?php  include("account.php");  //connect mysql database  session_start();  $dbc = mysqli_connect($hostname, $username, $password, $database) or die("unable connect mysql database");  echo "connected mysql<br>";  $user = $_post['name'];  $num = $_post['number'];  if(isset($_post['submit']))  {      if (empty ($user))       {          echo "you must enter unique username <br />";      }      if (empty ($num))       {          echo "you must enter id <br />";      }       	$query = "select * studentdb studentname = '". mysqli_real_escape_string($dbc,$user) ."' , studentid = '". mysqli_real_escape_string($dbc,$num) ."'" ;  	$result = mysqli_query($dbc,$query);  	if (mysqli_num_rows($result) == 1)   	{         /* if (isset($_post['list'] == '1'))  	   {  	   }  	   if (isset($_post['list'] == '2'))  	   {  	   } */  	}  	else  	{  		echo"unsuccessful login";  	}  session_destroy();  }  else  {  		echo "empty";  }  ?>

it works. change made commenting out section in-between if (mysqli_num_rows($result) == 1){}

this way: select should named , options have value

<td>     <select id = "mylist" name='listitems'>     <option value = "1">student registration</option>       <option value = "2">student transcript</option>   </select> </td>  if(isset($_post['listitems'] == '1')){  } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -