1

运行下面显示的代码时,出现此错误:(!)

Parse error: syntax error, unexpected T_SL in D:\Program Files\wamp\www\Fatz\Fatz Shopping Cart.php on line 13

代码:

<?php
$_Session['Basket'] = '';

$User = 'Username';
$Pass = 'Password';
$Database = 'database';

mysql_connect(localhost, $User, $Pass);
@mysql_select_db($Database) or die('Unable to select database');

$sql = <<<MySQL_Query; <!-- Error Line-->

CREATE TABLE IF NOT EXISTS Test
{
    ItemID int(3) unsigned NOT NULL auto_increment,
    Title varchar(128) NOT NULL default '',
    Price decimal(3,2) NOT NULL default '',
    PRIMARY KEY (ItemID)
} MySQL_Query;

mysql_query($sql);

INSERT INTO Test VALUES (1, 'What are we selling!', '10.00');

function ShoppingBaskItems()
{
    $basket = $_Session['Basket'];
    If(!isset($basket) || null($basket)) return '0 Items';
    $Items = explode(',', $basket);
    $Count = (count($Items) > 1) ? 'Count': '';
    return '<p><a href="Basket.php">'.count($Items).' items'.$Count.' </a></p>';
}

echo ShoppingBaskItems(); 
?>
4

2 回答 2

0

使用HEREDOCs时,token 需要单独一行,也不要$sql =行的 token 后面加分号。

$sql = <<<MySQL_Query

CREATE TABLE IF NOT EXISTS Test
{
    ItemID int(3) unsigned NOT NULL auto_increment,
    Title varchar(128) NOT NULL default '',
    Price decimal(3,2) NOT NULL default '',
    PRIMARY KEY (ItemID)
}
MySQL_Query;
于 2013-01-31T20:58:07.063 回答
0

< !-- ... -->是 HTML 注释标签。在 php 中你必须使用//,#/** */.

编辑:

$sql = "CREATE TABLE IF NOT EXISTS Test
{
ItemID int(3) unsigned NOT NULL auto_increment,
Title varchar(128) NOT NULL default '',
Price decimal(3,2) NOT NULL default '',
PRIMARY KEY (ItemID)
}";

mysql_query($sql);
于 2012-12-12T23:23:35.433 回答