PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if($_GET['remove']){
$removeid = $_GET['remove'];
mysql_query('DELETE FROM items WHERE itemname = "'. $removeid .'"');
}
$total_query = 'SELECT * FROM items WHERE cartid = "'. $cartid .'"';
$result = mysql_query($total_query, $prophot) or die(mysql_error());
$num = mysql_num_rows($result);
$i=0;
$grandtotal = 0;
while ($i < $num) {
$subtotal=mysql_result($result,$i,"subtotal");
$id=mysql_result($result,$i,"itemid");
$quantity=mysql_result($result,$i,"quantity");
$original=mysql_result($result,$i,"original");
$grandtotal += $subtotal;
$i++;
}
When a user clicks a remove link with "?remove=$itemname" in the end, I want the specified row to be removed from the database (the entire row) depending on the itemname. After it does that, I also want it to do calculations of the remaining rows. However, it's not doing that; it's only ignoring it. I have to click on an update button. I'd rather it be automated, rather than click 2 buttons to get the right calculations. Help would be appriciated.
feyd wrote:mayhaps you have a syntax error in your deletion query?
Now that you mention error, it's not the delete function that's wrong. $cartid is from a form, and the remove link is a text link, not a submit button. Sorry I over looked that little detail... been working on this problem since yesterday and barely realized it now. x_X;
Will the following work?
feyd wrote:mayhaps you have a syntax error in your deletion query?
Now that you mention error, it's not the delete function that's wrong. $cartid is from a form, and the remove link is a text link, not a submit button. Sorry I over looked that little detail... been working on this problem since yesterday and barely realized it now. x_X;
Will the following work?
update.php?remove=$itemid&cartid=$cartid
And then do:
$_GET['remove']
$_GET['cartid']
make sure you conceante the vars in the statment. has PHP spit out any errors?
feyd wrote:mayhaps you have a syntax error in your deletion query?
Now that you mention error, it's not the delete function that's wrong. $cartid is from a form, and the remove link is a text link, not a submit button. Sorry I over looked that little detail... been working on this problem since yesterday and barely realized it now. x_X;
Will the following work?
update.php?remove=$itemid&cartid=$cartid
And then do:
$_GET['remove']
$_GET['cartid']
make sure you conceante the vars in the statment. has PHP spit out any errors?
Nope, just ignored it completly. It removed the row correctly, but didn't do any calculations.
if(isset($_GET['remove'])){
$removeid = $_GET['remove'];
mysql_query("DELETE FROM items WHERE itemname = $removeid");
}
$total_query = "SELECT * FROM items WHERE cartid = $cartid";
$result = mysql_query($total_query, $prophot) or die(mysql_error());
$num = mysql_num_rows($result);
//testing
echo $num;
$i=0;
$grandtotal = 0;
while ($i < $num) {
// If $num is 0 then none of this happens
// Have you checked to make sure there is a number for $num?
$subtotal=mysql_result($result,$i,"subtotal");
$id=mysql_result($result,$i,"itemid");
$quantity=mysql_result($result,$i,"quantity");
$original=mysql_result($result,$i,"original");
$grandtotal += $subtotal;
$i++;
}