如何将用户信息和项目放入数据库中的同一个表中

时间:2017-09-12 05:59:29

标签: php mysql mysqli

我需要协助尝试从我正在循环的订单中获取信息。我需要能够将用户信息上方的订单信息输入到用户信息表中,这样我就可以将项目和用户信息提交到数据库中。但看起来我需要提交附加订购用户的多个项目。

这是部分代码

if(isset($_POST["get_cart_product"]) || isset($_POST["cart_checkout"])){
            $uid = $_SESSION["uid"];
            $sql = "SELECT * FROM cart WHERE user_id = `$uid` ";
            $run_query = mysqli_query($con,$sql);
            $count = mysqli_num_rows($run_query);
            if($count > 0){
                $no = 1;
                $total_amt = 0;
                while($row=mysqli_fetch_array($run_query)){
                    $id = $row["id"];
                    $pro_id = $row["p_id"];
                    $pro_name = $row["product_title"];
                    $pro_image = $row["product_image"];
                    $qty = $row["qty"];
                    $pro_price = $row["price"];
                    $total = $row["total_amt"];
                    $price_array = array($total);
                    $total_sum = array_sum($price_array);
                    $total_amt = $total_amt + $total_sum;
                    setcookie("ta",$total_amt,strtotime("+1 day"),"/","","",TRUE);
                    if(isset($_POST["get_cart_product"])){
                        echo "
                        <div class='row'>
                            <div class='col-md-3 col-xs-3'>$no</div>
                            <div class='col-md-3 col-xs-3'><img src='assets/product_images/$pro_image' width='60px' height='50px'></div>
                            <div class='col-md-3 col-xs-3'>$pro_name</div>
                            <div class='col-md-3 col-xs-3'>$.$pro_price.00</div>
                        </div>
                    ";
                    $no = $no + 1;
                    }else{
                        echo "
                            <div class='row'>
                                    <div class='col-md-2 col-sm-2'>
                                        <div class='btn-group'>
                                            <a href='#' remove_id='$pro_id' class='btn btn-danger btn-xs remove'><span class='glyphicon glyphicon-trash'></span></a>
                                            <a href='' update_id='$pro_id' class='btn btn-primary btn-xs update'><span class='glyphicon glyphicon-ok-sign'></span></a>
                                        </div>
                                    </div>";



                                    echo"

                                    <form action='user_information.php' id='form1' method='post'>
                                    <div class='col-md-2 col-sm-2'><img src='assets/product_images/$pro_image' width='50px' height='60'></div>
                                    <div class='col-md-2 col-sm-2'><input name='name' type='text' class='form-control qty' pid='$pro_name ' id='qty-$pro_name ' value='$pro_name ' ></div>
                                    <div class='col-md-2 col-sm-2'><input name='qty' type='text' class='form-control qty' pid='$pro_id' id='qty-$pro_id' value='$qty' ></div>
                                    <div class='col-md-2 col-sm-2'><input name='price' type='text' class='form-control price' pid='$pro_id' id='price-$pro_id' value='$pro_price' disabled></div>
                                    <div class='col-md-2 col-sm-2'><input name ='total' type='text' class='form-control total' pid='$pro_id' id='total-$pro_id' value='$total' disabled></div>
                                </div>";
                            }
                        }


                                    echo"

                                        <h3>Employee Information</h3>
                                             <label>Lan ID</label>
                                            <input type='text' name='lanId' id='lanId'  autocomplete='off'  class='form-control' >
                                            <label>Employee Name</label>
                                            <input type='text' name='employeeName' id='name'   autocomplete='off'  class='form-control'>
                                            <label>Department</label>
                                            <select name='department' id='department'  class='form-control'>
                                                <option value =''>Select Department...</option>
                                                <option value ='OTHER'> OTHER</option>

                                            </select>

                                        <label>Cost Center</label>
                                        <input type='text' class='form-control' name='costCenter' value=''>
                                        <br><br><br>
                                        <input type='submit' class='btn btn-primary' value='Submit'>

                                    </form>";

1 个答案:

答案 0 :(得分:0)

您不能将单引号&#39; 用于整数变量。 详细了解此When to use single quotes, double quotes, and backticks in MySQL

使用此查询

 $sql = "SELECT * FROM cart WHERE user_id = `$uid` ";

而不是这个

$sql = "SELECT * FROM cart WHERE user_id = '$uid'";