简体   繁体   中英

The selected value in dropdown list is not displaying

In this code i get values in dropdown but when i select data in dropdown it is not displayed selected value it shows undefined index category in line 66.So please help me.

             <form name="choose" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">

                 <?php 
                 $host="localhost";
                        $username="root";
                   $password="";
                  $db_name="slseatapp"; 

                 mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
                mysql_select_db("$db_name")or die("cannot select db");
                   $query="SELECT id,course_code FROM `coursemaster` ORDER BY `coursemaster`.`id`";
               $result = mysql_query($query);
                  ?>

                <select name=category>
                <?php
                while($nt=mysql_fetch_array($result)) {
                echo "<option value='".$nt['course_code']."'>".$nt['course_code']."              </option>";
                  }
                  ?>
                   </select>

               <input type="submit" name="submit" value="save category" />
               </form>

               <?php
           if($_GET){
            echo 'The course_code selected is'.$_POST['category'];
            }
            ?>

Use

<?php
    if($_GET){
        echo 'The course_code selected is'.$_GET['category'];
     }
?>

Or

<form name="choose" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
....
<?php
    if($_POST){
        echo 'The course_code selected is'.$_POST['category'];
     }
?>

I'm sure also someone will mention that mysql_ commands are deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM