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

				
					<?php

//===============add to cart===============
if(isset($_GET['add_to_cart']))
{
    
$cp_id=$_GET['cp_id'];
$cp_price = $_GET['cp_price'];
$cu_id = $_GET['cu_id'];
$qty = $_GET['qty'];
print_r($_GET);


$query="INSERT INTO temp_cart(qty,cp_price,cu_id,cp_product_id)values('$qty','$cp_price','$cu_id','$cp_id')";
$data=mysqli_query($con,$query);
if($data){
 echo "done";
}

}

?>
				
			
				
					<form action="" method="get">
  <p>QTY</p>
  <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'];?>">
  <br>
  <input type="submit" name="add_to_cart" class ="add-cart-btn" value="add to cart">  
                            
</form>
				
			
				
					<?php

$ip=$_SERVER['REMOTE_ADDR'];


$con=mysqli_connect("localhost","root","","shop");

$query="select * from temp_cart where cu_id='$ip'";
$data=mysqli_query($con,$query);



//=======================delete=====


if(isset($_GET['btndelete']))
{
    $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%">


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

      </tr>

        <?php 
            $amount1=0;
            $user=0;
            while($result= mysqli_fetch_assoc($data)){

        ?>

      <tr>
        <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>
      </tr>


      <?php
      $amount1+=$amount;
      echo $user= $result["cp_id"];
      } ?>

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

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

      </tr>

    </table>
    <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