简体   繁体   中英

dropdown menu mysql PHP

im new on PHP. i have problem on mydropdown menu program. i create table with name id and name .connected with mysql database this what i want, when i choose id 1 on dropdown menu 1 then dropdown menu 2 "show only" name "ex:dk" and other example 'id 2 " = name :"James " ....

     <?php
     /*---START -----*/
     $host   ='localhost';
     $user   ='root';
     $pass   ='';
     $db     ='sqldumb';

     $kon    =mysql_connect($host, $user, $pass);
       if(!$kon)
         die('EROR '.mysql_error());
          $dbkon  =mysql_select_db($db);
             if(!$dbkon)
              die('EROR '.mysql_error());

      /*-------END ------*/

      $sql = '';
      $result = mysql_query("SELECT * FROM cahkos");

      $sql .= '<select>';
        while($row = mysql_fetch_array($result))
            {
          $sql .= "<option value='".$row['id']."'>".$row['id']."</option>";
             }
            $sql .= '</select>';
       ?>


       <?php
       $sql1 = '';
       $result = mysql_query("SELECT * FROM cahkos Where name  = '.$row[id].' );

         $sql1 .= '<select>';
            while($row = mysql_fetch_array($result))
             {
                $pilihan1 .= "<option value='".$row['name']."'>".$row['name']."</option>";
             }
         $sql1 .= '</select>';
       ?>


    <html>
      <head></head>
      <body>
        <table align=center  >
         <tr>
            <td font-size=100>choose ID</td>
            <td><?php echo $sql;?></td>
         </tr>
         <tr>
            <td font-size=100>choose Name</td>
            <td><?php echo $sql;?></td>
         </tr>
       </table>
  </body>

This

$result = mysql_query("SELECT * FROM cahkos Where name  = '.$row[id].' );

should be this

$result = mysql_query("SELECT * FROM cahkos Where name  = '".$row['id']."'" );

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