Guest User

Untitled

a guest
Dec 21st, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1.  <?php
  2.    
  3.    
  4.     $user = '*';
  5.     $pass = '*';
  6.     $host = 'localhost';
  7.     $dbName = '*';
  8.    
  9.     mysql_connect($host, $user, $pass) or exit('Unable to connect to MySQL');
  10.     mysql_select_db($dbName) or exit('Could not select db');
  11.    
  12.    
  13.     $sql = 'SELECT * FROM categories';
  14.     $res = mysql_query($sql);
  15.    
  16.     $categories = array();
  17.    
  18.     while($row = mysql_fetch_assoc($res)){
  19.         $categories[] = $row;
  20.     }
  21.     $sql2 = 'SELECT * FROM manufacturers';
  22.     $res2 = mysql_query($sql2);
  23.    
  24.     $manufacturers = array();
  25.    
  26.     while($row2 = mysql_fetch_assoc($res2)){
  27.         $manufacturers[] = $row2;
  28.     }  
  29.    
  30.    
  31.    
  32.     ?>
  33.    
  34.     <html>
  35.    
  36.     <head>
  37.         <title>New product</title>
  38.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  39.         <link rel='stylesheet' href='css/main.css'>
  40.     </head>
  41.    
  42.     <body>
  43.         <div>
  44.             <a href ="categories.php">Categories</a> |
  45.             <a href ="manufacturers.php">Manufacturers</a> |
  46.             <a href ="products.php">Products</a>
  47.         </div>
  48.    
  49.         <hr />
  50.    
  51.         <form action="product-insert.php" method="POST">
  52.             <table>
  53.                 <tr>
  54.                     <td>Name</td>
  55.                     <td><input type="text" name="name" /></td>
  56.                 </tr>
  57.                 <tr>
  58.                     <td>Description</td>
  59.                     <td><textarea name="description" rows="10" cols="100"></textarea></td>
  60.                 </tr>
  61.                 <tr>
  62.                     <td>Category name</td>
  63.                     <td>   
  64.                            
  65.                             <select name='categoryID' >
  66.                                         <?php foreach( $categories as $category)?>
  67.                                         <option value="<?php echo $category['id']?>"> <?php echo $category['name'] ?></option>
  68.                             </select>
  69.                     </td>
  70.                 </tr>
  71.                 <tr>
  72.                     <td>Manufacturer name</td>
  73.                     <td>
  74.                             <select name='manufacturerID' >
  75.                                         <?php foreach( $manufacturers as $manufacturer)?>
  76.                                         <option value="<?php echo $manufacturer['id']?>"> <?php echo $manufacturer['name'] ?></option>
  77.                             </select>
  78.                    
  79.                     </td>
  80.                 </tr>
  81.                 <tr>
  82.                     <td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
  83.                 </tr>
  84.             </table>
  85.         </form>
  86.        
  87.     </body>
  88.     </html>
Advertisement
Add Comment
Please, Sign In to add comment