How to make ‘add to cart’ & stripe payment in PHP website


//===============add to cart===============
$cp_price = $_GET['cp_price'];
$cu_id = $_GET['cu_id'];
$qty = $_GET['qty'];

$query="INSERT INTO temp_cart(qty,cp_price,cu_id,cp_product_id)values('$qty','$cp_price','$cu_id','$cp_id')";
 echo "done";


					<form action="" method="get">
  <input type="number" name="qty">
  <input type="hidden" name="cp_id" value="<?php echo $result['p_id'];?>">
    <input type="hidden" name="p_id" value="<?php echo $result['p_id'];?>">
  <input type="hidden" name="cp_price" value="<?php echo $result['p_price'];?>">
  <input type="hidden" name="cu_id"  value="<?php echo $_SERVER['REMOTE_ADDR'];?>">
  <input type="submit" name="add_to_cart" class ="add-cart-btn" value="add to cart">  



$query="select * from temp_cart where cu_id='$ip'";


    $query="DELETE FROM temp_cart where cp_id='$_GET[did]' ";
    if (mysqli_query($con, $query)) {
        echo "Record deleted successfully";
      } else {
        echo "Error deleting record: " . mysqli_error($con);

					   <table border="1px" width="100%">

        <th> cp_product_id</th>
        <th>cp_price </th>
        <th> Qty</th>
        <th> Total price</th>
        <th> Action</th>


            while($result= mysqli_fetch_assoc($data)){


        <td> <?php echo $result["cp_product_id"];?></td>
        <td> <?php echo $result["cp_price"];?> </td>

        <td> <?php echo $result["qty"];?></td>

        <td> <?php  $amount=$result["qty"]* $result["cp_price"]; echo $amount;?></td>
        <td> <a href="?btndelete=del&did=<?php echo $result["cp_id"];?>"> <?php echo $result["cp_id"];?> Delete</a></td>

      echo $user= $result["cp_id"];
      } ?>

        <td colspan="3"> Total Price </td>

        <td colspan="2"><?php echo $amount1;?> </td>


    <a href="stripe/index.php?user=<?php echo $user;?>&amount=<?php echo $amount1;?>"> pay </a>
Stripe Test Card link
For those who face errors: Code to remove(hide) error: (Paste it in datacodes.php file)
					<?php error_reporting (E_ALL ^ E_NOTICE); ?>

Leave a Reply