Add Cookie with link

message from Ulitasch on 23 Jul 2004
HELP!
I want to add a cookie when clicking on a link. I am new to PHP and the
database (MySQL). I have found a tutorial to make a shopping cart at ZEND. From
this tutorial I have the script I put before the <html> which I attach to this
message here. It does not work, there is a parse error on line 2. (I have 2
Recordsets: one called HUIS, one called BEWAREN, BEWAREN has the column called
cart_id)

Can somebody help me? Why is this script not working? Does anybody has a more
simple script?
How can I add the funciton add_item when clicking on a link in PHP? (<a
href="<?php ; ?>">Remember</a>?

I would appreciate any help or tips to get a step further with this. I'm lost:(

<?php
?if(!isset($HTTP_COOKIE_VARS['cart_id']))?{
?????$cart_id?=?md5(uniqid(rand()));
?????setcookie("cart_id",?$cart_id,?time()?+?3600);
?}?else?{
?????$cart_id?=?$HTTP_COOKIE_VARS['cart_id'];
?}
class?cart?{

??var?$username?=?"myusername";
??var?$password?=?"mypassword";
??var?$database?=?"mydatabase";
??var?$hostname?=?"myhostname";

??var?$inv_table?=?"HUIS";
??????var?$cart_table?=?"BEWAREN";

function?cart($cart_id)?{
???$this->dblink?=?mysql_connect($this->hostname,
????????$this->username,?$this->password);
???mysql_select_db($this->database,?$this->dblink);
???$this->cart_id?=?$cart_id;
}
function?add_item($product,?$quantity)?{

???$qty?=?$this->check_item($product);
???$query?=?"SELECT quantity FROM "?.?$this->inv_table .
???????"?WHERE?product='$product'";
???$result?=?mysql_query($query,?$this->dblink);
???mysql_fetch_object($result);

???if($quantity?>?$result->quantity)?return?false;

???mysql_free_result($result);

???if($qty?==?0)?{

???????$query?=?"INSERT INTO ".$this->cart_table??
?????????.?" (session, product, quantity) VALUES ";
???????$query?.=?"('".$this->cart_id."', '$product', '$quantity')?";
???????mysql_query($query,?$this->dblink);
???}?else?{
???????$quantity?+=?$qty;
???????$query?=?"UPDATE ".$this->cart_table?.?
?????????"?SET?quantity='$quantity'?WHERE?session='".$this->cart_id."' AND ";
???????$query?.=?"product='$product'?";
???????mysql_query($query,?$this->dblink);
???}
???return?true;
?}
function?check_item($product)?{

???$query?=?"SELECT quantity FROM ".$this->cart_table.
????????????" WHERE session='".$this->cart_id."'?AND?product='$product'?";
???$result?=?mysql_query($query,?$this->dblink);

???if(!$result)?{
???????return?0;
???}
???$numRows?=?mysql_num_rows($result);

???if($numRows?!=?0)?{
???????$row?=?mysql_fetch_object($result);
???????return?$row->quantity;
???}
function?delete_item($product)?{
???$query?=?"DELETE FROM ".$this->cart_table." WHERE session='"
???????????????.?$this->cart_id."'?AND?product='$product'?";
???mysql_query($query,?$this->dblink);
}
function?clear_cart()?{
???$query?=?"DELETE FROM ".$this->cart_table." WHERE
session='".$this->cart_id."' ";
???mysql_query($query,?$this->dblink);
}
function?modify_quantity($product,?$quantity)?{

???if($quantity?<=?0) return?$this->delete_item($product);
???$query?=?"SELECT quantity FROM ".$this->inv_table.
?"?WHERE?product='$product'";
???$result?=?mysql_query($query,?$this->dblink);
???mysql_fetch_object($result);

???if($quantity?>?$result->quantity)?return?false;

???mysql_free_result($result);

???$query?=?"UPDATE ".$this->cart_table.
?????????"?SET?quantity='$quantity'?WHERE?session='".$this->cart_id."' ";
???$query?.=?"AND?product='$product'?";
???mysql_query($query,?$this->dblink);

???return?true;

?>
<?php require_once('Connections/connVastgoed.php'); ?>
<?php
mysql_select_db($database_connVastgoed, $connVastgoed);
$query_HUIS = "SELECT * FROM huizen";
$HUIS = mysql_query($query_HUIS, $connVastgoed) or die(mysql_error());
$row_HUIS = mysql_fetch_assoc($HUIS);
$totalRows_HUIS = mysql_num_rows($HUIS);

mysql_select_db($database_connVastgoed, $connVastgoed);
$query_BEWAREN = "SELECT * FROM bewaren";
$BEWAREN = mysql_query($query_BEWAREN, $connVastgoed) or die(mysql_error());
$row_BEWAREN = mysql_fetch_assoc($BEWAREN);
$totalRows_BEWAREN = mysql_num_rows($BEWAREN);
?>
 

Archived message: Add Cookie with link (Macromedia Dreamweaver Web Design)