MySQL Forums
Forum List  »  PHP

Is there anybody to help me in this code please???
Posted by: Zohra Pardesi
Date: June 08, 2019 01:41PM

Hi Friends,

I am learning website development from youtube tutorials and stuck at some point, it would be appreciated if someone help me out in code.

This is related to online store website.
If my database contains Lipstick 10 and Foundations 5.

User gets login and add both of above products into cart then she updates quantity of Lipstick to 12 and quantity of Foundation to 3.

in both above cases order place successfully and payment also gets done bill generate.............. which is not right as user's ordered quantity is more than the quantity available.

I tried to resolve the issue but as I am not expert and I am in learning phase so, I could not resolve the issue.

please have a look at my code and let me know how to resolve this issue???? I will really be grateful to you.



////////////////This is the Part of code where user gets login

else{
$u_email=$_SESSION['u_email'];
$ip_add=getIp();
$get_user=$conn->prepare("select * from zusers where u_email='$u_email'");
$get_user->setFetchMode(PDO:: FETCH_ASSOC);
$get_user->execute();
$row_user=$get_user->fetch();
$user_id=$row_user['user_id'];


$cart_item=$conn->prepare("select * from zuser_cart where ip_add='$ip' AND user_id='$user_id'");
$cart_item->setFetchMode(PDO:: FETCH_ASSOC);
$cart_item->execute();
$row=$cart_item->execute();
//$row=$cart_item->fetch();

$product_id=$row['product_id'];
$get_product=$conn->prepare("select * from zproducts where product_id='$product_id'");
$get_product->setFetchMode(PDO:: FETCH_ASSOC);
$get_product->execute();
$row_product=$get_product->fetch();
$q=$row_product['product_qty'];

/*if(isset($_POST['$update_qty'])){
if(($row['qty']) > $q){
echo "<script>alert('Your Required Quantity is more than the Quantity Available!);</script>";
}
}else{*/

$cart_empty=$cart_item->rowCount();

$grand_total=0;

if($cart_empty==0){
echo "<center><h2>No Item Found, Your Cart is Empty!!! &nbsp &nbsp;<a href='cat-detail.php?cat_id=1'>Continue Shopping</a></h2></center>";
}else {
if(isset($_POST['update_qty']) AND !empty($_POST['qty'])){
$quantity=$_POST['qty'];


if($quantity > $q){
echo "<script>alert('Your Required Quantity is more than the Quantity Available!');</script>";

foreach($quantity as $key=>$value){
$update_qty=$conn->prepare("update zuser_cart set qty=:value
where user_cart_id='$key'");
$update_qty->bindParam(":value", $value);
if($update_qty->execute()){
if(isset($_GET['checkout_cart'])){
echo "<script>window.open('checkout.php?checkout_cart','_self')</script>";
}else{
echo "<script>window.open('user-profile.php?mycart','_self')</script>";
}
}
}
}
}


echo "<table>
<tr>
<th>Image</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Sub Total</th>
<th>Remove Item</th>
</tr>
";
while($row=$cart_item->fetch()):
$product_id=$row['product_id'];
$get_product=$conn->prepare("select * from zproducts where product_id= '$product_id'");
$get_product->setFetchMode(PDO:: FETCH_ASSOC);
$get_product->execute();
$row_product=$get_product->fetch();
$q=$row_product['product_qty'];

echo
"<tr>
<td><img src='images/products_images/".$row_product['product_img1']."' /></td>
<td>".$row_product['product_name']."</td>
<td><input type='text' name='qty[".$row['user_cart_id']."]' value='".$row['qty']."' />
<input type='submit' name='update_qty' value='Save' /></td>
<td>".$row_product['product_disc_price']."</td>
<td>";
$qty=$row['qty'];
$product_price=$row_product['product_disc_price'];
$sub_total=$qty*$product_price;
echo $sub_total;
$grand_total=$grand_total+$sub_total;
echo "</td>
<td><a href='delete-cart.php?user_delete_id=".$row_product['product_id']."'>Delete</a></td>
</tr>";
endwhile;

Options: ReplyQuote


Subject
Written By
Posted
Is there anybody to help me in this code please???
June 08, 2019 01:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.