Jump to content
Larry Ullman's Book Forums

When Item Is Purchased (Through Paypal), Subtract One Number From Stock


Recommended Posts

I have somewhat of a dilemma.

 

When someone clicks on a Buy Now button and subsequently follows necessary steps to complete process of purchase, when that transaction is completed, in my product table, I want to subtract 1 from whatever value is in the field.

 

E.g. say product one is being purchased, prior to purchase in product table, there are 5 product one's in stock, when purchase is complete, subtract 1 from 5 (to get 4).

 

Here is my code

 

<?php
$title = "Like This Product, Buy It NOW!!!";
require ('includes/config.inc.php');
include ('./includes/header.html');
require (MYSQL);
include ('./includes/main.html');
if($id = isset($_GET['prodID']))
{
$query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'";
$r = mysqli_query($dbc, $query);
$showHeader = true;
echo "<div id='right'>";
while($row = mysqli_fetch_array($r))
{
if($showHeader)
{
	    //Display category header
echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] .  "<span>" . " #" . "</span>" . "</h1>";
echo "<div id='item'>"; // div class 'item'
echo "<div class='item_left'>";
echo "<p id='p_desc'>";
echo $row['prod_descr'];
echo "</p>";
echo "<p>" . "<span>" . "&pound" . $row['price'] . "</span>" . "</p>";
echo "</div>";
echo "<div class='item_right'>";
echo "<img src='db/images/".$row['image']."' />";
$showHeader = false;
echo "</div>";
?>
<p>
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J">
<input type="hidden" name="item_name" value="<?php echo $row['product']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['prodID']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</p>
<p>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me@mybusiness.com">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo $row['product']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p>
<?php
echo "</div>"; // End of div class 'item'
$strSQL = "SELECT prodID, product, price, image FROM product ORDER BY RAND() LIMIT 1"; 
$objQuery = mysqli_query($dbc, $strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysqli_fetch_array($objQuery)) 
{
echo "<div class='love'>";
echo "<h6>Like this......you'll love this!!!</h6>";
echo "<ul>";
echo "<li>" . "<img src='db/images/" . $objResult['image'] . "' width='50' height='50' />" . "</li>";
echo "<br />";
echo "<li>" . "<a href='item.php?prodID={$objResult['prodID']}' title='{$objResult['product']}'>" . $objResult['product'] . "</a>" . " - " . "&pound" . $objResult['price'] . "</li>";
echo "</ul>";
echo "</div>";
}
}
}
?>
<?php
echo "</div>";
}
include ('./includes/footer.html');
?>

 

 

How is this achievable please?

Link to comment
Share on other sites

That's the right idea, although the value wouldn't be in GET and you'd want to make sure it's safe to use in a query anyway.

 

The admin scripts show how to do this once an order is completed. You'd just apply that same code after the purchase has gone through instead.

Link to comment
Share on other sites

 Share

×
×
  • Create New...