【问题标题】:Syntax error ';' when querying database to table [duplicate]语法错误';'查询数据库到表时[重复]
【发布时间】:2019-06-26 18:58:20
【问题描述】:

我想知道这段代码有什么问题。我只是想将数据库查询到表中。谢谢大家

<?php
  while ($row = $query->fetch(PDO::FETCH_ASSOC))
  printf(
     "<tr>";
     "<th scope='row'>" . htmlentities($row['insrt_fullname']) . "</th>";
     "<td>" . htmlentities($row['insrt_username']) . "</td>";
     "<td>" . htmlentities($row['insrt_password']) . "</td>";
     "<td>" . htmlentities($row['insrt_email']) . "</td>";
     "<td>" . htmlentities($row['insrt_designation']) . "</td>";
     "<td>";
     '<a href=/tarp_admin/connection/delete_user.php?id=' . $user_id . ' 
class=\'badge badge-danger\' onclick="myFunction">Delete</a> <a 
href=/tarp_admin/connection/delete_user.php?id=' . $user_id . ' 
class=\'badge badge-warning\'>Edit</a>';
     "</td>";   
     "</tr>";
);
?>

解析错误:语法错误,意外';'在 C:\xammp\htdocs\tarp_admin\dashboard.php 第 344 行

【问题讨论】:

  • 为什么每行都有分号?
  • 哦.. 使用 printf() 后是否应该删除分号?
  • 是的,但我不确定多行上的这些字符串是否有效。
  • 嘿,感谢您注意到 ;在每个字符串行中。现在我得到了新的错误
  • 您应该只连接并存储在一个变量中并打印它。像 $html= ''; $html += "html";

标签: php html mysql pdo


【解决方案1】:

您在每一行都使用分号,这是一种错误的语法:您应该使用一个点来代替。 此外,由于您在例程中包含了如此多的 HTML,您可以改为使用:

<?php
  while ($row = $query->fetch(PDO::FETCH_ASSOC)):
?>

<tr>
<th scope='row'><?php print htmlentities($row['insrt_fullname']); ?></th>
/** ADD HERE ALL THE REST... */
</tr>

<?php
  endwhile;
?>

阅读更清晰。

【讨论】:

    【解决方案2】:

    使用.(点)代替;(分号)进行字符串连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 2015-08-23
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      相关资源
      最近更新 更多