T_SL错误,购物篮系统

时间:2012-12-12 23:20:56

标签: php

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

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

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

使用HEREDOCs时,令牌需要单独排在一行, not $sql =行上的令牌后面加一个分号。

$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;