Jump to content

Brunodgk

New Members
  • Posts

    3
  • Joined

  • Last visited

Brunodgk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for the advice! this is a small shop, that's why i used the IP to identify users, but like you said, this can give me serious problems, i need to change it... I'll read the link you posted, and study more about the PDO. I was following like 2 or 3 tutorials of ecommerce in internet, but all of them got some problems that i need upgrade it by my self, like valid/duplicated email, prevent sql injection, php injectin, xss attack, etc. My page functions.php got the mosts of the calcs, i was testing some things to implement later, at this point i stayed at the beginning. In last case i'll write every thing again. I got some products here to sell and i'm studing web languages to improve my curriculum too... in my university i only study C and Java or C#, i'm learning at home with internet, thanks you two again, the opinions and advice, i really appreciate it!
  2. Hi Barand, Thank you for the fast answer! I Appreciate it. I've done many things, i followed your answer, but i saw on the phpmyadmin that only the quantity(qty) of p_id = 1 changed . I'm new to PHP and Mysql, I want to learn and do this ecommerce, I've based on many tutorials, and I've come this far and intend to finish it. Thanks again for the help. <?php if(isset($_POST['update_cart'])){ $get_p_id = "select p_id from cart where ip_add='$ip'"; $run_p_id = mysqli_query($con, $get_p_id); $row_p_id = mysqli_fetch_array($run_p_id); $pcart_id = $row_p_id['p_id']; $qty= $_POST['qty']; if($qty<>0){ $get_cartp_qty = "select product_qty from products where product_id='$pro_id'"; $run_cartp_qty = mysqli_query($con,$get_cartp_qty); $row_cartp_qty = mysqli_fetch_array($run_cartp_qty); $max_qty = $row_cartp_qty['product_qty']; if($qty<=$max_qty){ $update_qty = "update cart set qty='$qty' where p_id='$pcart_id'"; $run_qty = mysqli_query($con, $update_qty); $_SESSION['qty'] = $qty; //comments of the other things i tried //$insert_qty_cart = "insert into cart (p_id,ip_add,qty) values ('$pcart_id','$ip','$qty')"; //$run_qty_cart = mysqli_query($con, $insert_qty_cart); $subtotal = $qty * $single_price; $total += $subtotal; } else{ echo "<script>alert('The quantity chosen exceeded the quantity of the DataBase!');</script>"; } } else{ echo "<script>alert('To remove the product, select the checkbox for the product and update your cart.');</script>"; } } ?>
  3. Hello, I started to make a PHP site with Mysql to create a store for some products. The person only adds 1 product in the cart, not being able to add it 2 times in it. Iin the cart.php, there is a place for the person to change the quantity according to the quantity of the product in the database stock. The problem is: when the person changes the quantity of the LAST product, the quantity changes to all other products in the cart, because the quantity is not linked to the respective "pro_id" (product ID from the quantity changed). The code in PHP when clicks on 'update cart' with the quantity defined by the person: <?php if(isset($_POST['update_cart'])){ $qty= $_POST['qty']; if($qty<> 0){ $get_qty = "select product_qty from products where product_id='$pro_id'"; $run_qty = mysqli_query($con,$get_qty); $row_qty = mysqli_fetch_array($run_qty); $max_qty = $row_qty['product_qty']; if($qty<=$max_qty){ $update_qty = "update cart set qty='$qty'"; $run_qty = mysqli_query($con, $update_qty); $_SESSION['qty'] = $qty; $total *= $qty; } else{ echo "<script>alert('The quantity chosen exceeded the quantity of the DataBase!');</script>"; } } else{ echo "<script>alert('To remove the product, select the checkbox for the product and update your cart.');</script>"; } } ?> Thanks for help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.