<?php
        connection check;
        select database;
        $sql="select * from category"
        mysql_query($sql);
        $prod_name=$_POST["prod_name"];

/pls tell me what to pass in cat_id down i have to take the select tag's value property then what should i pass pls help me........./
$cat_id="What to write here...."
sql1="insert into product(prod_name,cat_id) values('".$prod_name."','".$cat_id."');
$r=mysql_query($sql1);
?>

        <html>
            <form>
                <select id=prod name=prod>
                    <?php
                        while ($row=mysql_fetch_array($r))
                        {
                            echo "<option value=".$row["cat_id"].">$row["cat_name"] </option>";   
                        }
                        //can you tell me how to add the above value of cat_id and insert to table....
                    ?>
                </select>
            </form>
        </html>

When will you want to insert cat_id ? When the form has submitted ? You must have action to process server-side script. So, put action in your form via "action=somewhere" attribute. Somewhere could be server-side language php / jsp / asp file. Then, you can get the data in this page submitted by form and insert into database table with specific language (PHP-MySQL, ASP-MsSQL, etc.).

        <html>
            <form action="allprod.php" method="post">
                <select id=prod name=prod>
                    <?php
                        while ($row=mysql_fetch_array($r))
                        {
                            echo "<option value=".$row["cat_id"].">$row["cat_name"] </option>";   
                        }
                        //can you tell me how to add the above value of cat_id and insert to table....
                    ?>
                </select>
            </form>
        </html>

now pls tell me that should i pass $row["cat_id"] as a cat_id or some thing else which is selected.....

You can now get 'cat_id' in allprod.php by using $_POST['prod'], and then, go with your SQL query to insert that value into table.

so i should insert after the while loop and fire the sql query.....

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.