stock.php

    <td>Produk  :</td><br>
            <td>
              <select name="batch" onchange="submit();">
                <option value="-1" >-- Select Address --</option>
                <?php

                $username='root';
                $password='';

                $con = mysql_connect('localhost', $username, $password);
                mysql_select_db('snack', $con);

                $result = mysql_query("SELECT * FROM po");

                while($row = mysql_fetch_array($result))
                {
                }


                $data = array(
                '1'=>array('po'=>'1','namn'=>'name 1'),
                '2'=>array('po'=>'2','namn'=>'name 2'),
                '3'=>array('po'=>'3','namn'=>'name 3'),
                '4'=>array('po'=>'4','namn'=>'name 4'),
                '5'=>array('po'=>'5','namn'=>'name 5')
                );
                foreach($data as $item){
                echo "<option value='{$item['po']}'>{$item['namn']}</option>\r\n";
                }
                ?>
            </select>
            </td>    

What should I replace this with?

while($row = mysql_fetch_array($result))
                {
                }

I basically need to see the combo box filled with items from sql_query.

If anyone can help me fix the code, would be great.

what field you want in combo box from data base

place the following code after line 16

echo "<option value='".$row['po']."'>".$row['name']."</option>";

as arti18 said i dont know what your are going to place into your combobox

if you go like that then your database values will be plcaed into the combox

let me know if this is your answer or not

happy coding

      <?php
    $username='root';
    $password='';
    $con = mysql_connect('localhost', $username, $password);
    mysql_select_db('snack', $con);
    $result = mysql_query("SELECT * FROM po");
    ?>


     <td>Produk :</td><br>
    <td>
    <select name="batch" onchange="submit();">
    <option value="-1" >-- Select Address --</option>
  <?php 
    while($row = mysql_fetch_array($result))
    {
       ?>  
       <option value="<?php echo $row['field name'];?>">
        <?php echo $row['field name'];?></option>


    <?php } ?>

    </select>
    </td> 

try this put your field name in row index
warning:not tested

This error appears:

Notice: Undefined index: filed name in C:\xampp\htdocs\Innovation\script_shop\stock.php on line 51

line 51: <?php echo $row['field name'];?></option>

dear change field name to your field name that you use in database i am give you just a example

Notice: Undefined index: filed name in C:\xampp\htdocs\Innovation\script_shop\stock.php
are your prefering from arti18 code? did you just copied the error above cause i notice

filed name instead of field_name its either you mispelled it or the columns doesnt match

hai davy_yg

replace that 'field name' with column's name of the table what you are trying to place the values into combo box

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.