crazyj Posted May 28, 2007 Share Posted May 28, 2007 Hi I hope someone can help me, I'm very green when it comes to PHP/MySql and use dreamweaver to write most of the code. I'm just developing my own site and want to sell on-line. I have a couple of products in a database and can display them and send details to the paypal check out. What I want to do next is to atomatically subtract 1 from the Qty field in the database when someone adds an item to the cart. I'm sure it is simple when you know how. I've tried the on-line search but don't really know what question to ask in the first place I've got a testing page at http://www.jayne-herbert.co.uk/testing/details.php?item_number=3 which I keep breaking. Help .... Cheers CrazyJ Quote Link to comment https://forums.phpfreaks.com/topic/53282-subracting-from-database/ Share on other sites More sharing options...
redarrow Posted May 28, 2007 Share Posted May 28, 2007 $query="update whatever from whatever=whatever-1 where whatever='$whatever'"; Quote Link to comment https://forums.phpfreaks.com/topic/53282-subracting-from-database/#findComment-263300 Share on other sites More sharing options...
crazyj Posted May 28, 2007 Author Share Posted May 28, 2007 Thanks for the reply, sorry I'm so stupid. I can understand what you mean with the code, but I am still confused as to exactly where to put it. I've tried altering line number 39, maybe I'm putting it in the wrong place or getting the syntax wrong. Quote Link to comment https://forums.phpfreaks.com/topic/53282-subracting-from-database/#findComment-263308 Share on other sites More sharing options...
redarrow Posted May 28, 2007 Share Posted May 28, 2007 post ur current code ok Quote Link to comment https://forums.phpfreaks.com/topic/53282-subracting-from-database/#findComment-263312 Share on other sites More sharing options...
crazyj Posted May 28, 2007 Author Share Posted May 28, 2007 <?php require_once('../../Connections/moths.php'); ?> <?php require_once('../Connections/cn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE shop SET Published=%s, Status=%s, item_name=%s, item_type=%s, Catagory=%s, `Sub catagory`=%s, `Short description`=%s, `Long description`=%s, Qty=%s, amount=%s, Postage=%s, Image=%s, `Image 2`=%s, `Made by`=%s, front_page=%s, `Approximate size`=%s, Notes=%s WHERE item_number=%s", GetSQLValueString($_POST['Published'], "int"), GetSQLValueString($_POST['Status'], "text"), GetSQLValueString($_POST['item_name'], "text"), GetSQLValueString($_POST['item_type'], "text"), GetSQLValueString($_POST['Catagory'], "text"), GetSQLValueString($_POST['Sub_catagory'], "text"), GetSQLValueString($_POST['Short_description'], "text"), GetSQLValueString($_POST['Long_description'], "text"), GetSQLValueString($_POST['Qty'], "int"), GetSQLValueString($_POST['amount'], "text"), GetSQLValueString($_POST['Postage'], "text"), GetSQLValueString($_POST['Image'], "text"), GetSQLValueString($_POST['Image_2'], "text"), GetSQLValueString($_POST['Made_by'], "text"), GetSQLValueString($_POST['front_page'], "int"), GetSQLValueString($_POST['Approximate_size'], "text"), GetSQLValueString($_POST['Notes'], "text"), GetSQLValueString($_POST['item_number'], "int")); mysql_select_db($database_moths, $moths); $Result1 = mysql_query($updateSQL, $moths) or die(mysql_error()); $updateGoTo = "https://www.paypal.com/cgi-bin/webscr?submit.x=80&submit.y=10&add=1&cmd=_cart&business=jayne%40dingdong.me.uk&item_name=$item_name&item_number=$item_number&amount=$amount&no_note=1¤cy_code=GBP&lc=GB&bn=PP-ShopCartBF"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } $colname_Recordset1 = "-1"; if (isset($_GET['item_number'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['item_number'] : addslashes($_GET['item_number']); } mysql_select_db($database_cn, $cn); $query_Recordset1 = sprintf("SELECT * FROM jh_sales WHERE item_number = %s", GetSQLValueString($colname_Recordset1, "int")); $Recordset1 = mysql_query($query_Recordset1, $cn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"><!-- InstanceBegin template="/Templates/1_main.dwt" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="doctitle" --> <title>Jayne Herbert's web site</title> <!-- InstanceEndEditable --> <link href="../css/1_main.css" rel="stylesheet" type="text/css" > <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> </head> <body> <table width="600" border="1" align="center"> <tr> <td> <!-- InstanceBeginEditable name="title" --><!-- #BeginLibraryItem "/Library/title_main.lbi" --><a href="../index.php"><img src="../images/global/title_main.jpg" alt="Jayne Herbert's web site" width="600" height="254" border="0"></a><!-- #EndLibraryItem --><!-- InstanceEndEditable --> </td> </tr> <tr> <td bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="EditRegion1" --> <h1>Jayne's Cornish Crafts </h1> <!-- InstanceEndEditable --></td> </tr> <tr bgcolor="#FFFFFF"> <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" valign="top"><table width="600" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="205" valign="top" bgcolor="#241E10"><!-- InstanceBeginEditable name="menu" --><!-- #BeginLibraryItem "/Library/menu_main.lbi" --> <link href="../css/1_main.css" rel="stylesheet" type="text/css"> <div id="button"> <ul> <li><a href="../index.php">Home</a></li> <li><a href="../contact.php">Contact </a></li> <li><a href="../web/index.php">Web services</a></li> <li><a href="../cornwall/index.php">Cornwall</a></li> <li><a href="../wildlife/index.php">Wildlife</a></li> <li><a href="../pets/index.php">Pets</a></li> <li><a href="../crafts/index.php">Crafts</a></li> <li><a href="../gallery/index.php">Photographs</a></li> <li><a href="../links.php">Favourite links</a></li> </ul> </div> <!-- #EndLibraryItem --><!-- InstanceEndEditable --></td> <td width="395" valign="top"><table width="400" border="0" align="center" cellpadding="10" cellspacing="0" id="content"> <tr> <td><!-- InstanceBeginEditable name="EditRegion2" --> <table width="100%" border="0" align="center"> <tr align="left" valign="top"> <td width="60%"><div align="center"> <h2><?php echo $row_Recordset1['item_name']; ?></h2> <p><img src="/images/sales/<?php echo $row_Recordset1['Image']; ?>" alt="<?php echo $row_Recordset1['item_name']; ?>" border="1" /></p> <p><?php echo $row_Recordset1['Long description']; ?><br /> <?php echo $row_Recordset1['Approximate size']; ?><br /> Made by: <?php echo $row_Recordset1['Made by']; ?><br /> <?php echo $row_Recordset1['Sub catagory']; ?> £<?php echo $row_Recordset1['amount']; ?>, postage <?php echo $row_Recordset1['Postage']; ?></p> <p><br /> Only <?php echo $row_Recordset1['Qty']; ?> available<br /> <br /> <br /> <style type="text/css"> </style> <br /> </p> </div> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td> <div align="center"> <p> <input type="hidden" name="Published" value="0" size="32" /> <input type="hidden" name="Status" value="unavailable" size="32" /> <input type="hidden" name="item_name" value="<?php echo $row_Recordset1['item_name']; ?>" size="32" /> <input type="hidden" name="item_type" value="<?php echo $row_Recordset1['item_type']; ?>" size="32" /> <input type="hidden" name="Catagory" value="<?php echo $row_Recordset1['Catagory']; ?>" size="32" /> <input type="hidden" name="Sub_catagory" value="<?php echo $row_Recordset1['Sub catagory']; ?>" size="32" /> <input type="hidden" name="Short_description" value="<?php echo $row_Recordset1['Short description']; ?>" size="32" /> <input type="hidden" name="Long_description" value="<?php echo $row_Recordset1['Long description']; ?>" size="32" /> <input type="hidden" name="Qty" value="<?php echo $row_Recordset1['Qty']; ?>" size="32" /> <input type="hidden" name="amount" value="<?php echo $row_Recordset1['amount']; ?>" size="32" /> <input type="hidden" name="Postage" value="<?php echo $row_Recordset1['Postage']; ?>" size="32" /> <input type="hidden" name="Image" value="<?php echo $row_Recordset1['Image']; ?>" size="32" /> <input type="hidden" name="Image_2" value="<?php echo $row_Recordset1['Image 2']; ?>" size="32" /> <input type="hidden" name="Made_by" value="<?php echo $row_Recordset1['Made by']; ?>" size="32" /> <input type="hidden" name="front_page" value="<?php echo $row_Recordset1['front_page']; ?>" size="32" /> <input type="hidden" name="Approximate_size" value="<?php echo $row_Recordset1['Approximate size']; ?>" size="32" /> <input type="hidden" name="Notes" value="<?php echo $row_Recordset1['Notes']; ?>" size="32" /> <input type="hidden" name="item_number" value="<?php echo $row_Recordset1['item_number']; ?>" /> <input type="hidden" name="MM_update" value="form1" /> </p> <p> <input type="submit" value="Add to shopping cart" /> </p> </div></td> </tr> </table> </form> <p> </p> <p align="center">I use Paypal to process orders, but you do not need a Paypal account, you can use your credit card.</p> <p align="center">Please see <a href="craft_service.php">service details</a> for notes about Paypal and postage.</p> <p> </p></td> </tr> <tr align="left" valign="top"> <td> </td> </tr> </table> <link href="../css/bluedog.css" rel="stylesheet" type="text/css" /> <!-- InstanceEndEditable --></td> </tr> </table> <p> </p></td> </tr> <tr> <td valign="top" bgcolor="#241E10"> </td> <td valign="top"><a href="../index.php"><img src="../images/global/logo.gif" alt="Jayne Herbert web design penzance" name="logo" width="104" height="67" border="0" class="image_right" id="logo" ></a></td> </tr> <tr> <td colspan="2" valign="top" bgcolor="#241E10"><a href="../index.php"><img src="../images/global/footer.jpg" alt="Jayne Herbert web design Penzance" name="footer" width="600" height="57" border="0" id="footer" ></a></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </body> <!-- InstanceEnd --></html> <?php mysql_free_result($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53282-subracting-from-database/#findComment-263313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.