我有这个PHP代码来显示一个sql表。我正在尝试设置一段代码删除行。我在互联网上看到了一个例子。但是当我在line24上使用该代码时,我得到了这个(解析错误:语法错误,意外'删除'(T_STRING),期待','或';')错误。我该怎么办?
<html>
<body>
<?php
$conn=odbc_connect('MOS2.41','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM Docnumber";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table border=1>
<tr>";
echo "<th>PatId</th>";
echo "<th>Docnumber</th>";
echo "<th>Delete</th>
</tr>";
while ($row = odbc_fetch_row($rs))
{
$PatId=odbc_result($rs,"PatId");
$Docnumber=odbc_result($rs,"Docnumber");
echo "<tr><td>$PatId</td>";
echo "<td>$Docnumber</td>";
echo "<td><a href="delete.php?id={$row['id']}">Delete row</a></td><tr/>";
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>
答案 0 :(得分:1)
您的网址未正确包含在:
echo "<td><a href="delete.php?id={$row['id']}">Delete row</a></td><tr/>";
^ here
使用\
:
echo "<td><a href=\"delete.php?id={$row['id']}\">Delete row</a></td><tr/>";
答案 1 :(得分:0)
更改
echo "<td><a href="delete.php?id={$row['id']}">Delete row</a></td><tr/>";
要
echo '<td><a href="delete.php?id='. $row['id'].'">Delete row</a></td><tr/>';
错误地使用了{
。
<html>
<body>
<?php
$conn=odbc_connect('MOS2.41','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM Docnumber";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table border=1>
<tr>";
echo "<th>PatId</th>";
echo "<th>Docnumber</th>";
echo "<th>Delete</th>
</tr>";
while ($row = odbc_fetch_row($rs))
{
$PatId=odbc_result($rs,"PatId");
$Docnumber=odbc_result($rs,"Docnumber");
echo "<tr><td>$PatId</td>";
echo "<td>$Docnumber</td>";
echo '<td><a href="delete.php?id='. $row['id'].'">Delete row</a></td><tr/>';
}
odbc_close($conn);
echo "</table>";
?>
</body>
</html>