-1

This is the checkout code. my values of the query are not functioning. It's not inserting please help me fix this.

            $q = "select * from cart";
            $quer = mysqli_query($con, $q);

            while($q_row = mysqli_fetch_array($quer)){
            $order_id = $q_row['order_id'];
            $prod_id = $q_row['p_id'];

            //get p_id
            $p_id_q = "select * from products where prod_id = '$prod_id'";
            $run_products = mysqli_query($con, $p_id_q);
            $row_product = mysqli_fetch_array($run_products);
            $product_id = $row_product['prod_id'];
            $product_name = $row_product['prod_name'];


            $add_order = "insert into orders (order_id,p_id,prod_name,status) values ('$order_id','$prod_id','$prod_name','Pending')";
            $run_add = mysqli_query($con, $add_order);

            }
        }

        ?>
Michael
  • 65
  • 6
  • whats the error?? what you get as value of $run_add?? – RohitS Oct 10 '16 at 20:09
  • Check for errors. Since you're using mysqli, save yourself the headache and use prepared statements/parameter binding, or you're going to leave yourself wide open for SQL injection and issues with variable quoting. – aynber Oct 10 '16 at 20:10
  • `$prod_name` do you mean `$product_name` ? – Sharlike Oct 10 '16 at 20:11
  • the error is the query "insert into" is not inserting to my orders table. – Michael Oct 10 '16 at 20:14

1 Answers1

0

u have declared $product_name but using $prod_name in insert query

Hassan Tahir
  • 134
  • 9