Parse error: syntax error, unexpected ';' in C:\wamp\www\12.01.2015 Class 01\Coffee Website\Model\CoffeeModel.php on line 106
<?php
require ("Entities/CoffeeEntity.php");
// contains database related code for the coffee type
class CoffeeModel
{
// Get all coffee types from the database and return them in an array
function GetCoffeeTypes()
{
require 'Credentials.php';
//Open connection and Select database
mysql_connect($host, $user, $password) or die (mysql_error());
mysql_select_db($database);
$result = mysql_query("SELECT DISTINCT type FROM coffee") or
die(mysql_error());
$types = array();
// Get data from databse
while($row = mysql_fetch_array($result))
{
array_push($types, $row[0]);
}
/ Close connection and return
mysql_close();
return $types;
}
// GET coffeeEntity objects from the database and return them in an array.
function GetCoffeeByType($type)
{
require 'Credentials.php';
// Open connection and select database
mysql_connect($host, $user, $password) or die (mysql_error());
mysql_select_db($database);
$query = "SELECT * FROM coffee WHERE type LIKE '$type'";
$result = mysql_query($query) or die (mysql_error());
$coffeeArray = array();
//GET Data from Database
while ($row = mysql_fetch_array($result))
{
$name = $row[1];
$type = $row[2];
$price = $row[3];
$roast = $row[4];
$country = $row[5];
$image = $row[6];
$review = $row[7];
// Create Coffee objects and store them in an array
$coffee = new CoffeeEntity (-1, $name, $type, $price, $roast, $country, $image, $review);
array_push($coffeeArray, $coffee);
}
// CLose connection and return result
mysql_close();
return $coffeeArray;
}
function GetCoffeeById($id)
{
require 'Credentials.php';
// Open connection and select database
mysql_connect($host, $user, $password) or die (mysql_error());
mysql_select_db($database);
$query = "SELECT * FROM coffee WHERE id = $id";
$result = mysql_query($query) or die (mysql_error());
//GET Data from Database
while ($row = mysql_fetch_array($result))
{
$name = $row[1];
$type = $row[2];
$price = $row[3];
$roast = $row[4];
$country = $row[5];
$image = $row[6];
$review = $row[7];
// Create Coffee
$coffee = new CoffeeEntity ($id, $name, $type, $price, $roast, $country,
$image, $review);
}
// CLose connection and return result
mysql_close();
return $coffee;
}
function InsertCoffee (CoffeeEntity $coffee)
{
$query = sprintf ("INSERT INTO coffee
(name, type, price, roast, country, image, review)
VALUES
('%s','%s','%s','%s','%s','%s','%s')",
mysql_real_escape_string($coffee->name),
mysql_real_escape_string($coffee->type),
mysql_real_escape_string($coffee->price),
mysql_real_escape_string($coffee->roast),
mysql_real_escape_string($coffee->country),
mysql_real_escape_string("Images/Coffee/". $coffee->image),
$this->PerformQuery($query);
}
function UpdateCoffee($id, CoffeeEntity $coffee)
{
$query =("UPDATE coffee
SET name = '%s', type = '%s', price = '%s', roast = '%s',
country = '%s', image = '%s', review = '%s'
WHERE id = $id"
mysql_real_escape_string($coffee->name),
mysql_real_escape_string($coffee->type),
mysql_real_escape_string($coffee->price),
mysql_real_escape_string($coffee->roast),
mysql_real_escape_string($coffee->country),
mysql_real_escape_string("Images/Coffee/". $coffee->image),
$this->PerformQuery($query);
);
$this-> PerformQuery($query);
}
function DeleteCoffee($id)
{
$query = "DELETE FROM coffee WHERE id = $id";
$this->PerformQuery($query);
}
function PerformQuery ($query)
{
require ('Credentials.php');
mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($database);
//Execute query and close connection
mysql_query($query) or die(mysql_error());
mysql_close();
}
}
?>