Advertisement
Guest User

Simple PHP / HTML / MySQL dropdown list

a guest
Jan 27th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "root";
  6. $dbname = "yourdb";
  7.  
  8.     $con=mysqli_connect($host,$username,$password,$dbname);
  9.  
  10.     // Check connection
  11.     if (mysqli_connect_errno())
  12.     {
  13.     echo "Failed to connect to MySQL: " . mysqli_connect_error();
  14.     }
  15.  
  16.     // Retrieve product info
  17.     $list=mysqli_query($con, "select products_reference from products");
  18.  
  19.     ?>
  20.     <form>
  21.         <select>
  22.             <option value="">--- Select ---</option>
  23.             <?php while($row_list=mysqli_fetch_assoc($list)) { ?>
  24.                 <option value="<? echo $row_list['column_id']; ?>"> // Change column_id into id of item
  25.                     <? echo $row_list['column_reference'];?> // Change column_refrerence into item name
  26.                 </option>
  27.             <?php } ?>
  28.         </select>
  29.     </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement