0

well hello guys want to ask for your help in improving this code. Please help me. First things first I have a database name called quotation and it has 4 fields namely Id, Date, Product and Price. Well I want to get the name of the product in the drop down and its corresponding price then store it in the database. My teacher told me I'll be using arrays but I don't really know how to use it specially that I'm new with this kind. Please help me :) thanks in advance

<?php
    include("connect.php");

    if(isset($_REQUEST['submit'])){
        $cabbage=$_REQUEST['cabbage'];
        $prcabbage=$_REQUEST['PRcabbage'];
        $beans=$_REQUEST['beans'];
        $prbeans=$_REQUEST['PRbeans'];
        $carrots=$_REQUEST['carrots'];
        $PRcarrots=$_REQUEST['PRcarrots'];

        $date=$_REQUEST['date'];

        $query="INSERT into quotation(Id, Date, Product, Price) VALUES ('', '$date', 
        '$cabbage', '$prcabbage', '$beans', '$prbeans', '$carrots','$prcarrots')";

        mysql_query=($query);
        $count=mysql_affected_rows;

        if($count==1){
            echo "Data Sent!";
        }else{
            echo "Error";
        }
    }
?>
<html>
    <table border="1" cellpadding="2">
    <form name="form" method="get" action="form.php">

        <label>Date of quotation</label>
        <input type="text" name="date"><br/>

        <th>Description</th>
        <th>Bid Price</th>

        <tr>
        <td><select name="cabbage">
            <option>cabbage</option>
        </select></td>
        <td><input type="text" name="PRcabbage"></td>
        </tr>

        <tr>
        <td><select name="beans">
            <option>Beans</option>
        </select></td>
        <td><input type="text" name="PRbeans"></td>
        </tr>

        <tr>
        <td><select name="carrots">
            <option>Carrots</option>
        </select></td>
        <td><input type="text" name="PRcarrots"></td>
        </tr>
    </table>
        <br/><br/>
        <input type="Submit" name="submit" value="submit">
    </form>

</html>
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Leslie Joy
1

Ok, it looks as though your table is set up incorrectly, try to make it as easy to update as possible. You'll be better off doing something like this:

product_id (Primary Key, int)
productname (varchar (20))
price (float?)

0

ah ok, thanks. But how do you actually get the values from every drop down you created and insert them into your database?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.