的config.php
<?php
try{
connection = new PDO("mysql:dbname=9lessons;host=localhsot", "root", "");
}catch(PDOException $error){
echo $error->getMessage();
}
?>
main.php
<?php
include ('config.php');
foreach ($connection->query('SELECT * FROM message LIMIT 9') as $row)
{
$msg = $row['msg'];
$mes_id=$row['mes_id'];
$up=$row['up'];
$down=$row['down'];
?>
<div class="main">
<div class="box1">
<div class="up">
<a href=""class="vote" id="<?php echo $mes_id?>" name="up">
<?php echo $up; ?></a></div>
<div class="down">
<a href="" class="vote" id="<?php echo $mes_id; ?>" name="down">
<?php echo $down; ?></a></div>
</div>
<div class="box2"><?php echo $msg; ?></div>
</div>
<?php } ?>
当我运行上面的代码时,我收到如下错误消息:
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\config.php on line 3
答案 0 :(得分:3)
变量以$
开头:
$connection = new PDO("mysql:dbname=9lessons;host=localhsot", "root", "");
任何时候你有Parse error: syntax error, unexpected
- 找到意想不到的东西并慢慢回溯寻找语法错误。