every one , I face small problem I hope any one help me . It is e-shopping site , I just want little help. the idea after pressing Add to cart link it will transfare him to cart page, there is two link edit and remove , the remove will remove the item , and that is working . but when some one press edit link , textbox in the quantity column will appear ans save link will appear also once he press save , there will be update in the databse
The problem is : 1- how to transfer textbox value from case "showupdate" to another case "savee"?
I 've tried to $qq=$_POST['qun'];
and send the variable in the link of save beside the action and id but it doesnot work always it said undefined variable 'qun'
The second problem is : the textbox and save link appears in all items on the cart , i do not want that , I want just that item who i press edit beside it , to change to textbox and save link will apper.
i know that i 've put while loop , that is just to make sure that the id of item got it when press link edit only who will get textbox and save link
here is the code please please help me,
switch($action){
case "add":
{$id=$_REQUEST['id'];
$query='insert into cart values("1",'.$id.',"1")';
$result=mysql_query($query);
header("location:cart.php?action=show");
break;
}
case "remove":
{ $id=$_REQUEST['id'];
echo $id;
$query='delete from cart where itemId='.$id.'' or die(mysql_error());
$result = mysql_query($query) or die(mysql_error());
header ("location:cart.php?action=show");
break;}
case "showupdate":
{ $id=$_REQUEST['id'];
$sql2="select * from cart";
$result2= mysql_query($sql2);
while($row2 = mysql_fetch_array($result2))
{ if ( $id == $row2['itemId'])
{ $totalCost =0;
$query = "select * from cart inner join items on cart.itemId = items.itemId";
$result = mysql_query($query);
?>
<table width="100%" border="1">
<?php while($row = mysql_fetch_array($result)){
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td><img src="<?php echo $row["image"];?>" height="50" width="50"/></td>
<td><?php echo $row["itemName"]; ?></td>
<td>SR<?php echo $row["itemPrice"]; ?></td>
<td>
<form method="POST" name="form1">
<input type = "text" name="qun" value="<?php echo $row['qty'];?>" size="10"/>
</form>
</td>
<td><a href="cart.php?action=savee&id=<?php echo $row["itemId"]; ?>">Save</a></td>
<td><a href="cart.php?action=remove&id=<?php echo $row["itemId"]; ?>">Remove</a></td>
</tr>
<?php }
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
$totalCost = $totalCost + ($row["qty"] * $row["itemPrice"]); ?>
<tr> <td colspan="2"> <a href="homestore.php">Keep Shopping</a></td>
<td colspan="2"> <b>Total: SR<?php echo $totalCost; ?></b></td></tr>
</table>
<?php }
} break;}
case "savee":
{ $id=$_REQUEST['id'];
$sql='update cart set qty='.$_POST['qun'].'where itemId='.$id.''or die(mysql_error());
$result=mysql_query($sql)or die(mysql_error());
header ("location:cart.php?action=show");
break;
}
case "show":
{
$totalCost =0;
$query = "select * from cart inner join items on cart.itemId = items.itemId";
$result = mysql_query($query);
?>
<table width="100%" border="1">
<?php while($row = mysql_fetch_array($result))
{
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td><img src="<?php echo $row["image"];?>" height="50" width="50"/></td>
<td><?php echo $row["itemName"]; ?></td>
<td>SR<?php echo $row["itemPrice"]; ?></td>
<td><a href="cart.php?action=showupdate&id=<?php echo $row["itemId"]; ?>">edit</a></td>
<td><a href="cart.php?action=remove&id=<?php echo $row["itemId"]; ?>">Remove</a></td>
</tr>
<?php }
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
$totalCost = $totalCost + ($row["qty"] * $row["itemPrice"]); ?>
<tr> <td colspan="2"> <a href="homestore.php">Keep Shopping</a></td>
<td colspan="2"> <b>Total: SR<?php echo $totalCost; ?></b></td></tr>
</table>
<?php break; }
}?>
If I click add link , it will transfare the action="add" and the id of that item after that it will insert to switch statment in add case because there is header ("location..") it will transfare immeddiatly to show case which show us the table edit + remove link once click on edit link it will go to showupdate case which show textbox + save link once click save it will go to savee case.