Please help me!
I have migrated a shopping cart script from my test environment (PHP 4) to a live server (PHP 5).
When I open the site I get the following message:
Now I have been through every line of code & checked all the {}, " and ; are correctly in place but the error persists.
Please can anyone help?
The code is below:
I have migrated a shopping cart script from my test environment (PHP 4) to a live server (PHP 5).
When I open the site I get the following message:
Code:
Parse error: syntax error, unexpected T_STRING in /home/xxx/public_html/test/shoppingcart.php on line 1
Now I have been through every line of code & checked all the {}, " and ; are correctly in place but the error persists.
Please can anyone help?
The code is below:
Code:
<?php
class cart
{ //open cart class
var $username = "xxx";
var $password = "xxx";
var $database = "xxx";
var $hostname = "localhost";
var $inv_table = "inventory";
var $cart_table = "shopping";
function cart($cart_id)
{ //open cart id
$this->dblink = mysql_connect($this->hostname, $this->username, $this->password);
mysql_select_db($this->database, $this->dblink);
$this->cart_id = $cart_id;
} //close cart id
//add & update (via add to basket) functions
function add_item($product, $category, $price, $quantity, $colour)
{ //open cart func
$qty = $this->check_item($product, $colour);
if($qty == 0)
{ //open qty 0
$query = "INSERT INTO ".$this->cart_table . " (session, product, category, price, quantity, colour) VALUES ('".$this->cart_id."', '$product', '$category', '$price', '$quantity', '$colour') ";
mysql_query($query, $this->dblink);
//print $query;
} //close qty 0
else
{ //open qty <1
$quantity += $qty;
$query = "UPDATE ".$this->cart_table . " SET quantity='$quantity' WHERE session='".$this->cart_id."' AND
product='$product'and colour='$colour' ";
mysql_query($query, $this->dblink);
print $query;
} //close qty <1
return true;
} //close cart func
//view quantitys
function check_item($product, $colour)
{ //open check items func
$query = "SELECT quantity FROM ".$this->cart_table. " WHERE session='".$this->cart_id."' AND product='$product' and colour='$colour'";
$result = mysql_query($query, $this->dblink);
if(!$result)
{ //open result arg
return 0;
} //close result func
$numRows = mysql_num_rows($result);
if($numRows != 0)
{ //open not 0 arg
$row = mysql_fetch_object($result);
return $row->quantity;
} //close not 0 arg
} //close check items func
//delete item function
function delete_item($product, $colour)
{ //open query
$query = "DELETE FROM ".$this->cart_table." WHERE session='" . $this->cart_id."' AND product='$product'and colour='$colour'";
mysql_query($query, $this->dblink);
} //close query
//empty basket
function clear_cart()
{ //open query
$query = "DELETE FROM ".$this->cart_table." WHERE session='".$this->cart_id."' ";
mysql_query($query, $this->dblink);
} //close query
//update quantity
function modify_quantity($product,$quantity,$colour)
{ //open query
if($quantity <= 0) return $this->delete_item($product);
$query = "UPDATE ".$this->cart_table. " SET quantity='$quantity' WHERE session='".$this->cart_id."'AND product='$product'and
colour='$colour'";
mysql_query($query, $this->dblink);
return true;
} //close query
function get_contents()
{//open function
//get stuff in the cart and return in indexed array
$q1 = "SELECT * FROM ". $this->cart_table. " WHERE session='".$this->cart_id."'";
$incart_r = mysql_query($q1,$this->dblink) or die(mysql_error());
$numrows=mysql_num_rows($incart_r);
if ($numrows == 0)
{ $contents==0;} //open & close argument
else
{//open argument
$contents = array();
while($incart = mysql_fetch_array($incart_r))
{ //open query
//get the item's price first
$q2 = "SELECT price FROM ". $this->cart_table. " WHERE product='".$incart["product"]."' ";
$price_row = mysql_query($q2) or die(mysql_error());
$price = mysql_fetch_row($price_row);
//build array of info
$item = array($incart['product'],$incart['category'],$incart['quantity'],$incart['price'],$incart['colour']);
array_push($contents,$item);
} //close query
} //close argument
return $contents;
} //close function
function cart_subtotal()
{//open function
$contents = $this->get_contents();
$total = 0;
for($i=0; $i < count($contents); $i++)
{ //open arg
$total = $total + ($contents[$i][3]* $contents[$i][2]);
} //close arg
$total = "£".number_format($total, 2, '.', '');
return $total;
}//close function
function cart_total()
{//open function
$contents = $this->get_contents();
if ($contents==0)
{ //open arg
//no items
$total = "£0.00";
return $total;
}//close arg
else
{ //open arg
//items
$total = 0;
for($i=0; $i < count($contents); $i++)
{//open calc
$total = $total + (($contents[$i][3]* $contents[$i][2]));
}//close calc
//postage argument - change $stdpost if postage to be added
$stdpost="0.00";
$total = $total + $stdpost;
$total = "£".number_format($total, 2, '.', '');
return $total;
}//close arg
} //close function
function post_total()
{//open func
$contents = $this->get_contents();
$total = 0;
for($i=0; $i < count($contents); $i++)
{//open
$total = $total + ($contents[$i][4]* $contents[$i][2]);
}//close
$total = "£".number_format($total, 2, '.', '');
return $total;
}//close func
function quant_items()
{ //open func
$contents = $this->get_contents();
$q = 0;
for($i=0; $i < count($contents); $i++)
{//open
$q = $q + $contents[$i][2];
}//close
return $q;
} //close func
function single_total()
{//open func
$contents = $this->get_contents();
$total = 0;
for($i=0; $i < count($contents); $i++)
{//open
$total = $total + ($contents[$i][4]* $contents[$i][2]);
}//close
$total = "£".number_format($total, 2, '.', '');
return $total;
}//close func
} //close class
?>