-5

The code to populate combo box from database

<td>Item Name:</td>
    <td><select name="items">
        <option value="0" selected="selected"> Choose</option>
        <?php
         while($row = mysql_fetch_assoc($query))
         {
            $category = $row["ItemName"];
            echo "$category";
        ?>
        <option value= <?php $category ?> > <?php echo  $category ?> </option>
        <?php
      }?>
      </select></td>

Code for submit

<td><input type="submit" name="newItem" value="New Item"/></td>

PHP code is:

 <?php
    if(isset($_POST['newItem']))
    {
    $item=$_POST['items'];
    $sel=mysql_query("select ItemID from itemmaster where ItemName='$item'");
    while($row2 = mysql_fetch_array($sel))
    {
               //code
        }
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
  • Value should be inside quotes `` – Awlad Liton Mar 13 '14 at 07:20
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Mar 13 '14 at 07:21
  • You already have code in the question to get the value from your select element. What is the problem? – Quentin Mar 13 '14 at 07:21
  • A combobox is a UI control that is a combination (hence the name) of a drop down menu (which is what you get with a select in HTML) and a text input (an input of type text). HTML doesn't have any native controls that are represented as comboboxes. If you want one then you would have to build it with a pile of JavaScript. You have "a select element". – Quentin Mar 13 '14 at 07:23
  • 1
    What has a combo-box got to do with PHP? – Fr0zenFyr Mar 13 '14 at 07:24

1 Answers1

0

Value should be inside quotes

change:

<option value= <?php $category ?> > <?php echo  $category ?> </option>

to

<option value= "<?php $category ?> "> <?php echo $category ?> </option>
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53