Ошибка разбора: синтаксическая ошибка, неожиданный ‘;’ в C: \ wamp \ www \ 12.01.2015 Класс 01 \ Сайт кофе \ Модель \ CoffeeModel.php на линии 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();
}
}
?>
Это прямо здесь, в функции InsertCoffee
:
$query = sprintf ("INSERT INTO coffee etc etc"// Snip
mysql_real_escape_string("Images/Coffee/". $coffee->image),
// You never had the closing paren ) to sprintf()
$this->PerformQuery($query);
Вам нужно избавиться от запятой после финала mysql_real_escape_string()
и затем закройте вызов sprintf()
с );
,
Первая ошибка в строке 42 (отсутствует вторая косая черта, чтобы сделать ее комментарием):
/ Close connection and return
Измените это на:
// Close connection and return
Следующая ошибка в строке 188 (значение для проверки отсутствует), чтобы избежать синтаксической ошибки и вставить пустую строку для проверки, измените ее с:
mysql_real_escape_string("Images/Coffee/". $coffee->image),
чтобы:
mysql_real_escape_string("Images/Coffee/". $coffee->image), "");
Следующая ошибка в строке 210 (отсутствует sprintf), поэтому измените
$query =("UPDATE coffee
чтобы:
$query = sprintf("UPDATE coffee
Тогда строка 207 изменится
WHERE id = $id"
в
WHERE id = $id",
Тогда строка 222 изменится
$this->PerformQuery($query);
чтобы:
""
$this->PerformQuery($query);
Кидает ошибку. Не уверен, что вы пытаетесь сделать, но это неправильный синтаксис.