php - 有语法错误但不知道在哪里

标签 php html mysql ajax

好吧,我有一个表生成器,里面有mysql db的数据。

先上代码:

PHP

while($result = mysqli_fetch_assoc($SQL)){
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Name')' contentEditable = 'true'>" . $result['Name'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Username')' contentEditable = 'true'>" . $result['Username'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Email')' contentEditable = 'true'>" . $result['Email'] . "</p>");
          $tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Grade')' contentEditable = 'true'>" . $result['Grade'] . "</p>" );
          $tbl->addCell("<input type = 'button' class = 'Edit-TBB' value = 'Edit'>
          <input type = 'button' class = 'Delete-TBB' value = 'Delete'>");
          $tbl->addRow();
      }

AJAX

function editTable(id, new_text, column) {
          $.ajax({
              url: "../PHP/Configuracion/edit_grade.php",
              type: "POST",
              data: 'id='+id+'&text='+new_text.innerText,
              success: function(data){
                  alert(column);
              }
          });
      }

问题是:

我有这个 'editTable(". $result['id_user'] . ", this, 'Name')'

In Chrome, it show me this

如果我更改 Chrome 中的代码,如 this ...它有效,但我不知道我需要在代码编辑器中更改什么。

我需要更改什么?

谢谢!

最佳答案

您必须为您的 onBlur 值使用双引号,因为您使用单引号将 js 字符串表示为参数。为此,您需要在 php.ini 中转义双引号。因此,将 addCell 调用更改为如下所示:

addCell("<p onBlur=\"editTable(" . $result['id_user'] . ", this, 'Name')\" contentEditable = 'true'>");

关于php - 有语法错误但不知道在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44092842/

相关文章:

php - 将空值从ajax传递到php脚本

PHP类,继承,实现

javascript - 我可以使用我的 jQuery AJAX post 方法数据键连接到我的 php 文件吗?

javascript - 登录后查看 HTML 内容

javascript - 如何将 href 添加到 SharePoint 上的按钮

mysql - 删除存储在数据库 WooCommerce 中的优惠券

MySQL:我如何将特定数量的空白行插入表中

php - Wordpress - 父主题覆盖子样式

html - CSS:在没有 rgba 的情况下设置背景不透明度

php - Cake PHP 返回带有空值的记录