I just wonder why in the code below isn't working. it stop at the line: "$result = mysql_query...". but if I copy the code from the addToCart function into the switch statement after the "case'add'", then no problem at all. What's wrong with the use of function here?
*Actually, I was first put the function "addToCart" in a separate file, and since I couldn't get it work so I move it to here.
and at the time the Yellowgreen Part of the code are working fine.
ccp
==========================================================
<?php
require_once('library/config.php');
$action = (isset($GET['action']) && $GET['action'] != '') ? $_GET['action'] : 'view';
switch ($action) {
case 'add' :
addToCart();
break;
...
}
function addToCart()
{
$productId = (int)$GET['pid'];
$qty = (int)$GET['qty'];
$sid = session_id();
$sql = "SELECT productID FROM shopcart WHERE productID = $productId AND shopcart.clientID = '$sid'";
$result = mysql_query($sql, $testconn) or die(mysql_error());
$totalRows = mysql_num_rows($result);
}
$query_cartset = "SELECT * FROM shopcart, product WHERE shopcart.productID = product.ID AND shopcart.clientID = '$sid'";
$cartset = mysql_query($query_cartset, $testconn) or die(mysql_error());
$row_cartset = mysql_fetch_assoc($cartset);
$totalRows_cartset = mysql_num_rows($cartset);
?>