what is the problem that cant update quantity for same produ
Posted: Fri Apr 15, 2011 8:26 am
hi,i face some problem that i cant update quantity for the same products..if the user want add their same product,i need to add current quantity and quantity in the database..but i failed to update..when i click the addtocart button,it will link to a blank page in saveCart.php.i also cant insert the data into database..it must be my code have problem...can anyone help me to correct my code??very urgent..
thanks in advanced...
saveCart.php
when i put these code,i also cant insert the data into database..
view_product.php
cls_users.php
thanks in advanced...
saveCart.php
Code: Select all
<?php
session_start();
require_once 'config.php' ;
require_once 'application.php' ;
//var_dump($_FILES);
$id = $_SESSION['id'];
$username = $_SESSION['username'];
$pid=$_POST['pid'];
$pname=$_POST['pname'];
$price=$_POST['price'];
$quantity=$_POST['quantity'];
$query = "SELECT * FROM products WHERE pid = $pid";
$result = mysql_query($query);
$row=mysql_fetch_row($result);
$pid = $row[1];
$pname = $row[3];
$price = $row[5];
$promo = $row[6];
if ($promo != '0.00')
{ $uprice = $promo; }
else
{ $uprice = $price; }
$query1 = 'SELECT * FROM register WHERE id = "'. mysql_real_escape_string($id) . '"';
$result1 = mysql_query($query1);
$row1=mysql_fetch_row($result1);
$query2 = 'SELECT quantity FROM cart WHERE id = "'. mysql_real_escape_string($id) . '"
AND pid = "'. mysql_real_escape_string($pid) . '"';
$result2 = mysql_query($query2);
while($row2=mysql_fetch_object($result2))
{
$uprice= $row->uprice;
$pid=$row->pid;
$pname=$row->pname;
if ($data = mysql_fetch_object($result2)){
$newQuantity = 0;
$newQuantity = $data->$quantity;
$newQuantity += $quantity;
$query3 = 'UPDATE cart set quantity ="'.$newQuantity.'" WHERE id = "'. mysql_real_escape_string($id) . '"
AND pid = "'. mysql_real_escape_string($pid) . '"';
$result3 = mysql_query($query3);
echo"<script>alert(\"Updated Successfully!\")</script><script>window.location='home.php?id=$id'</script>";
}
else{
$query4 = 'INSERT INTO cart SET id = "' . mysql_real_escape_string($id) . '",
username = "' . mysql_real_escape_string($username) . '",
pid= "' . mysql_real_escape_string($pid) . '",
pname = "' . mysql_real_escape_string($pname) . '",
uprice = "' . mysql_real_escape_string($uprice) . '",
quantity = "' . mysql_real_escape_string($quantity) . '"';
$result4 = mysql_query($query4);
echo"<script>alert(\"Saved Successfully!\")</script><script>window.location='home.php?id=$id'</script>";
}
}
?>Code: Select all
$query2 = 'SELECT quantity FROM cart WHERE id = "'. mysql_real_escape_string($id) . '"
AND pid = "'. mysql_real_escape_string($pid) . '"';
$result2 = mysql_query($query2);
while($row2=mysql_fetch_object($result2))
{
$uprice= $row->uprice;
$pid=$row->pid;
$pname=$row->pname;
if ($data = mysql_fetch_object($result2)){
$newQuantity = 0;
$newQuantity = $data->$quantity;
$newQuantity += $quantity;
$query3 = 'UPDATE cart set quantity ="'.$newQuantity.'" WHERE id = "'. mysql_real_escape_string($id) . '"
AND pid = "'. mysql_real_escape_string($pid) . '"';
$result3 = mysql_query($query3);
echo"<script>alert(\"Updated Successfully!\")</script><script>window.location='home.php?id=$id'</script>";
}Code: Select all
<?php
session_start();
require_once 'application.php' ;
require_once 'config.php' ;
$id = $_SESSION['id'];
include "cls_users.php";
$users = new Users;
$fm = "view_product.php";
$pid=$_GET['pid'];
$result_data = $users->getAllProductDetails($pid);
$cid = $result_data[2];
$pname = $result_data[3];
$pdesc = $result_data[4];
$price = $result_data[5];
$promo = $result_data[6];
$ppic1 = $result_data[10];
$ppic2 = $result_data[11];
$ppic3 = $result_data[12];
$ppic4 = $result_data[13];
$ppic5 = $result_data[14];
$result_data2 = $users->getCategoryDetails($cid);
$cname = $result_data2[2];
$query_update = "UPDATE products SET count = count+1 where pid = '$pid'";
$result = mysql_query($query_update);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<title>.:: home ::.</title>
</head>
<body>
<table width="952px" border="0" cellspacing="0" cellpadding="0" valign="top" align="center">
<tr>
<td align="center"><?php include "header.php"; ?></td>
</tr>
<tr><td><img src="picture/purple_line.jpg" /></td></tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="300px" height="600px" valign="top" align="center"> <?php include "menu.php";?>
</td>
<td width="12px"> </td>
<td width="630px"background="picture/content1.png" style="background-repeat:no-repeat;" valign="top"><table width="80%" border="0">
</table>
<table width="100%" border="0">
<tr>
<td><table width="100%" border="0"><tr>
<td width="28%"> </td>
<td width="38%"><img src="picture/icon_cart.jpg" /></td></tr></table></td>
</tr>
<tr>
<td><form action="saveCart.php" method="post" >
<input type="hidden" value = "<?php echo $pid;?>" name = "pid">
<div align="left"> <table width="100%" border="0">
<tr>
<td align="left"><span class="txt_yellow1"> <?php echo $pname;?></span></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="left"><span class="txt_white"><span class="txt_white"> </span></span><span class="txt_yellow"> Description:</span><span class="txt_white"> <?php echo $pdesc;?></span></td>
</tr>
<tr>
<td align="left"><table width="100%" border="0">
<tr>
<td align="left"><span class="txt_white"> </span><span class="txt_yellow">Price: </span><span class="txt_white">RM</span>
<?php
if($promo!="0.00")
{
echo "<span style=\"text-decoration:line-through\" class=\"txt_white\">$price</span>
<span style=\"font-size:20px; color:#FF0000\">$promo</span>";
}
else
{
echo "$price";
}
?> </td>
<td width="12"><label for="quantity"class="txt_yellow">Quantity:</label></td>
<td align="left" width="10" ><input type="text" name="quantity" value=""size="5"id=" $pid"></td>
<input type="hidden" value = "<?php echo $pid;?>" name = "pid">
<td><input type="submit" name="submit" value="AddToCart"></td>
</tr>
</table></td>
</tr>
</table></div></form></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
Code: Select all
<?php
include "cls_connectDB.php";
class Users{
function Users()
{
$connection = new ConnectDB;
$connection->open_connection();
}
function getAllProductDetails($pid)
{
$query = "SELECT * FROM products WHERE pid = '$pid'";
$result = mysql_db_query("nagels", $query);
$result_data = mysql_fetch_row($result);
return $result_data;
}
}//end class
?>