我在PHP回显输出HTML时出现问题,我无法弄清楚我的引号有什么问题。
echo '<tr><td>' . $row[1] . '</td><td>' . $row[2] . '</td><td>' . $row[3] . '</td><td><input type=\"button\" class=\"button-link\" value=\"Create\" onClick=\"location.href="fyp.comeze.com/createassignment.php?module_id=\"' . row[2] . "\''/></td><td><input type=\"button\" class=\"button-link\" value = \"Edit\" onClick=\"\" /></td><td><input type=\"button\" class=\"button-link\" value = \"PDF\" onClick=\"\" /></td></tr>';
这是我的错误:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in \public_html\FYP\modules.php on line 24
非常感谢任何帮助或帮助。
答案 0 :(得分:2)
你似乎有2个问题
$ row [2]的第二次出现缺少它的$前缀。 接下来,您似乎正在转义HTML,就好像您使用的是双引号,而您不是。
尝试以下方法:
echo
'<tr>',
'<td>', $row[1], '</td>',
'<td>', $row[2], '</td>',
'<td>', $row[3], '</td>',
'<td>',
'<input type="button" class="button-link" value="Create" onClick="location.href=\"fyp.comeze.com/createassignment.php?module_id=', $row[2], '\"" />',
'</td>',
'<td>',
'<input type="button" class="button-link" value="Edit" onClick="" />',
'</td>',
'<td>',
'<input type="button" class="button-link" value="PDF" onClick="" />',
'</td>',
'</tr>';
答案 1 :(得分:0)
您在第二次引用$
时错过了row[2]
。应该是$row[2]
。
答案 2 :(得分:0)
此代码应修复引用问题..
echo '<tr><td>' . $row[1] . '</td><td>' . $row[2] . '</td><td>' . $row[3] . '</td>
<td><input type="button" class="button-link" value="Create" onClick="location.href="fyp.comeze.com/createassignment.php?module_id="' . $row[2] . '"></td>
<td><input type="button" class="button-link" value = "Edit" onClick="" /></td><td><input type="button" class="button-link" value = "PDF" onClick="" /></td></tr>';
答案 3 :(得分:0)
我认为这是您为HTML元素的属性添加的转义字符。如果将整个字符串用单引号括起来,则不需要这些。
例如,class=\"button-link\"
应该是'class="button-link"';