【问题标题】:I get this Error again n again [duplicate]我一次又一次地得到这个错误[重复]
【发布时间】:2015-08-25 01:17:46
【问题描述】:

解析错误:语法错误,第 22 行 C:\xampp\htdocs\ad10.php 中的文件意外结束

<?php

$c=mysql_connect("localhost","root","") or die("Connection Error");

mysql_select_db("staff") or die("database error");

$q=mysql_query("select * from teachers");

echo "<table border=1>

<th>Number</th>

<th>Name</th>

<th>Shift</th>

<th>Class</th>

<th>Update</th>

<th>Remove</th>";

while($row=mysql_fetch_array($q))

{

?>

<tr>

    <td><? echo $row['Name'];?></td>

    <td><? echo $row['Shift'];?></td>

    <td><? echo $row['Class'];?></td>

</tr>

<?

}

?>

    </table>

任何人都可以请通知代码的问题.....

【问题讨论】:

  • 在选择数据库、mysql_select_db("staff",$c) 或 die("database error") 中插入您的连接;

标签: php mysql


【解决方案1】:

您没有启用短标签,因此您在 &lt;? ?&gt; 内的结束卷曲 } 不会关闭 while 循环。

<?php
$c=mysql_connect("localhost","root","") or die("Connection Error");
mysql_select_db("staff") or die("database error");
$q=mysql_query("select * from teachers");
echo "<table border=1>
<th>Number</th>
<th>Name</th>
<th>Shift</th>
<th>Class</th>
<th>Update</th>
<th>Remove</th>";
while($row=mysql_fetch_array($q)) {
?>
<tr>
    <td><?php echo $row['Name'];?></td>
    <td><?php echo $row['Shift'];?></td>
    <td><?php echo $row['Class'];?></td>
</tr>
<?php
}
?>    
</table>

实际上在写完这篇文章后注意到nameshiftclass 都是短标签,所以它们也不会被输出,所以也许这是错误的?

【讨论】:

  • 如果 OP 的服务器上没有启用短标签,那么是;这也会导致文件解析错误的意外结束。
  • @Sheikh Salman Aziz,请让我们知道这是否解决了问题。
猜你喜欢
  • 2022-11-05
  • 2013-04-27
  • 2023-04-06
  • 1970-01-01
  • 2013-09-28
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多