我得到解析错误任何人都可以帮助我

时间:2015-01-16 21:14:38

标签: php mysql coffeescript

  

解析错误:语法错误,意外&#39 ;;'在C:\ wamp \ www \ 12.01.2015第106行的Class 01 \ Coffee Website \ Model \ CoffeeModel.php

<?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();

}

}

?>

3 个答案:

答案 0 :(得分:1)

这就在函数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()关闭对);的通话。

答案 1 :(得分:1)

第一个错误在第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);

为:

""

答案 2 :(得分:0)

 $this->PerformQuery($query);

抛出错误。不确定你要做什么,但这是不正确的语法。