添加新的下拉数据

时间:2018-02-20 01:54:18

标签: php

在我添加项目的按钮中,在类别区域中,我的类别是修复我只能从数据库本身手动添加类别,我想在类别区域的下拉列表中插入新数据。

I want new dropdown menu

This is my php file

这是我的addproduct.php,在我的PHP代码中添加了一个产品。

addproduct.php
<?php
    include('session.php');

    $name=$_POST['name'];
    $category=$_POST['category'];
    $price=$_POST['price'];
    $supplier=$_POST['supplier'];
    $qty=$_POST['qty'];

    $fileInfo = PATHINFO($_FILES["image"]["name"]);

    if (empty($_FILES["image"]["name"])){
        $location="";
    }
    else{
        if ($fileInfo['extension'] == "jpg" OR $fileInfo['extension'] == "png") {
            $newFilename = $fileInfo['filename'] . "_" . time() . "." . $fileInfo['extension'];
            move_uploaded_file($_FILES["image"]["tmp_name"], "../upload/" . $newFilename);
            $location = "upload/" . $newFilename;
        }
        else{
            $location="";
            ?>
                <script>
                    window.alert('Photo not added. Please upload JPG or PNG photo only!');
                </script>
            <?php
        }
    }

    mysqli_query($conn,"insert into product (product_name,categoryid,product_price,product_qty,photo, supplierid) values ('$name','$category','$price','$qty','$location', '$supplier')");
    $pid=mysqli_insert_id($conn);

    mysqli_query($conn,"insert into inventory (userid, action, productid, quantity, inventory_date) values ('".$_SESSION['id']."', 'Add Product', '$pid', '$qty', NOW())");

    ?>
        <script>
            window.alert('Product added successfully!');
            window.history.back();
        </script>
    <?php
?>

这是我的addmodal.php,其中主要是我的html和css文件。

addmodal.php
<!-- Add Product -->
<div class="modal fade" id="addproduct" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <center><h4 class="modal-title" id="myModalLabel">Add New Product</h4></center>
            </div>

            <div class="modal-body">
            <div class="container-fluid">
                <form role="form" method="POST" action="addproduct.php" enctype="multipart/form-data">
                    <div class="container-fluid">
                    <div style="height:15px;"></div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Name:</span>
                        <input type="text" style="width:400px; text-transform:capitalize;" class="form-control" name="name" required>
                    </div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Category:</span>
                        <select style="width:400px;" class="form-control" name="category">
                            <?php
                                $cat=mysqli_query($conn,"select * from category");
                                while($catrow=mysqli_fetch_array($cat)){
                                    ?>
                                        <option value="<?php echo $catrow['categoryid']; ?>"><?php echo $catrow['category_name']; ?></option>
                                    <?php
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Supplier:</span>
                        <select style="width:400px;" class="form-control" name="supplier">
                            <?php
                                $sup=mysqli_query($conn,"select * from supplier");
                                while($suprow=mysqli_fetch_array($sup)){
                                    ?>
                                        <option value="<?php echo $suprow['userid']; ?>"><?php echo $suprow['company_name']; ?></option>
                                    <?php
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Price:</span>
                        <input type="text" style="width:400px;" class="form-control" name="price" required>
                    </div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Quantity:</span>
                        <input type="text" style="width:400px;" class="form-control" name="qty">
                    </div>
                    <div class="form-group input-group">
                        <span style="width:120px;" class="input-group-addon">Photo:</span>
                        <input type="file" style="width:400px;" class="form-control" name="image">
                    </div>            
                    </div>
            </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Cancel</button>
                <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>
                </form>
            </div>
        </div>
    </div>
</div>

非常感谢

0 个答案:

没有答案