I having trouble writing the query for inner join? For show function, I want join CART and ITEM table base the share attribute SKU. Here is the complete code for script. I got parse error Unexpected T_string when parsing query for show function.
<?php
include ("header.php");
// Set Oracle Environment
PutEnv("ORACLE_SID=course");
PutEnv("ORACLE_HOME=/afs/cad/solaris/oraclient10.2");
PutEnv("LD_LIBRARY_PATH=/afs/cad/solaris/oraclient10.2/lib");
// Connect to Oracle
$conn = OCILogon("username", "pass", "course");
// performing specific operation
switch ($_GET['action'])
{
case 'Add':
AddItem($_GET['id'], $_POST['qty']);
showCart();
break;
case 'Remove':
removeItem($_GET['id']);
showCart();
break;
case 'Update':
updateItem($_POST['id'], $_POST['qty']);
showCart();
break;
default:
showCart();
}
function AddItem($skuNum, $qty)
{
$sku_id = $skuNum;
$cookie = session_id();
$quantity = $qty;
$stmt = oci_parse($conn, "SELECT COUNT(*) FROM CART WHERE cookieid = :cookie AND
SKU = :sku");
// bind the variable
oci_bind_by_name($stmt, ":sku_id", $sku_id, -1);
oci_bind_by_name($stmt, ":cookie", $cokkie, -1);
oci_bind_by_name($stmt, ":quantity", $quantity, -1);
ociexecute($stmt);
$rows = ocifetchstatement($stmt, $data);
// if this item is not in the cart then add it to the cart
if ($row == 0)
{
// insert into three of four columns of CART table
$quantity = $qty;
$cookie = session_id();
$sku_id = $skuNum;
$stmt = oci_parse($conn, "INSERT INTO CART VALUES(
inc.NEXTVAL, :cookie, :sku_id, :quantity)");
// bind the input and output variable
oci_bind_by_name($stmt, 'cookie', $$cookie, -1);
oci_bind_by_name($stmt, ':sku_id', $sku_id, 1-1);
oci_bind_by_name($stmt, ':quantity', $quantity, -1);
oci_execute($stmt);
}
else
{
// if the the item already in the cart, then update the quantity
updateItem($skuNUM, $qty);
}
ocifreestatement($stmt);
}
function removeItem($skuNum)
{
// assing session id and item SKU
$cookie = session_id();
$sku_id = $skuNUM;
$stmt = oci_parse($conn, "DELETE FROM CART WHERE COOKIE_ID = :cookie AND
SKU = :sku_id");
// bind the input and output variable
oci_bind_by_name($stmt, ':cookie', $cookie, -1);
oci_bind_by_name($stmt, ':sku_id', $sku_id, -1);
oci_execute($stmt);
ocifreestatement($stmt);
}
// Update the item's quantity
function updateItem($skuNum, $qty)
{
$cookie = session_id();
$sku_id = $skuNUM;
$quantity = $qty;
// parse the query
$stmt = oci_parse($conn, "UPDATE CART SET QTY = :quantity WHERE COOKIE_ID = :cookie AND
SKU = :sku_id);
// bind the input and output variable
oci_bind_by_name($stmt, ':cookie', $cookie, -1);
oci_bind_by_name($stmt, ':sku_id', $sku_id, -1);
oci_bind_by_name($stmt, ':quantity', $quantity, -1);
oci_execute($stmt);
ocifreestatement($stmt);
}
function showCart()
{
// get the information from ITEM table by joining it with Cart table
// base on item SKU and cookie match
$cookie = session_id();
$stmt = oci_parse($conn, "SELECT * FROM CART JOIN ITEM ON CART.SKU = ITEM.SKU
WHERE CART.COOKIE = :cookie");
oci_execute($stmt);
oci_bind_by_name($stmt, ':cookie', $cookie, -1);
while (ocifetchinto($stmt, $rows, OCI_ASSOC))
{
// update the total price
$total += ($rows['QTY'] * $rows['PRICE']);
print"<td width = \"5%\" height = 25>
<font face = verdana size = 1 color = black>" . $rows['NAME'] . "</font></td>";
print"<td width = \"55%\" height = 25>
<font face = verdana size = 1 color = black>" . "$". $rows['PRICE'] . "</font></td>";
print"<td width = \"10%\" height = \"25\">
<font face = verdana size = 1 color = black>
<a href = \"cart.php?action=Remove&id = \" . $rows['SKU'] . \">" . "Remove</a></font></td></tr>";
}
ocifreestatement(stmt);
}
ocilogoff($conn);
?
</body></html>