-3

我有表名为ipcam (camera id,camera name,camera model,IP address, Url, Port). 我能够成功地从 MySQL 数据库中检索数据。现在我打算做的是在表的末尾添加一个额外的字段Delete- 这是超链接并通过将 id 发送到页面来删除该行deletecam.php是代码:

<?php                               
$result = mysql_query("SELECT * from ipcam WHERE user_id = {$user_id}");
echo"<table border=5 colspan=6> <tr><th>IP CAMERA ID &nbsp;&nbsp;</th><th>IP CAMERA NAME &nbsp;&nbsp;</th><th>CAMERA MODEL&nbsp;&nbsp;</th> <th>IP ADDRESS&nbsp;&nbsp;</th> <th>URL&nbsp;&nbsp;</th> <th>PORT&nbsp;&nbsp;</th><th>DELETE&nbsp;&nbsp;</th></tr>";
while($row = mysql_fetch_array($result)){
    echo "<tr>
    <td>" . $row['id'] . "</td>
    <td>" . $row['name'] . "</td>
    <td>" . $row['model'] . "</td>
    <td>" . $row['ipaddress'] . "</td>
    <td>" . $row['url'] . "</td>
    <td>" . $row['port'] . "</td>      
    <td> echo"<html><h3>"; <a href="/deletecam.php?id= <?php echo urlencode($row['id']); ?> "> Delete </a>  echo"</h3></html>"; </td></tr>"; 

}
echo "</table>";
?>

但是,当我运行此代码时遇到奇怪的问题,错误是:

Parse error: syntax error, unexpected '>' in C:\xampp\htdocs\IPCAM\cameralist.php on line 176

当我尝试在代码中包含超链接时,删除错误。我是在语法上做错了什么,还是不可能做这样的事情。

4

2 回答 2

1

试试这个,你不应该得到错误。你没有结束回声字符串。

 <?php 

    $result = mysql_query("SELECT * from ipcam WHERE user_id = {$user_id}");


    echo"<table border=5 colspan=6> <tr><th>IP CAMERA ID &nbsp;&nbsp;</th><th>IP CAMERA NAME &nbsp;&nbsp;</th><th>CAMERA MODEL&nbsp;&nbsp;</th> <th>IP ADDRESS&nbsp;&nbsp;</th> <th>URL&nbsp;&nbsp;</th> <th>PORT&nbsp;&nbsp;</th><th>DELETE&nbsp;&nbsp;</th></tr>";

    while($row = mysql_fetch_array($result))
    {

    echo "<tr>
    <td>" . $row['id'] . "</td>
    <td>" . $row['name'] . "</td>
    <td>" . $row['model'] . "</td>
    <td>" . $row['ipaddress'] . "</td>
    <td>" . $row['url'] . "</td>
    <td>" . $row['port'] . "</td>"  ; // i missed a " here
    ?>
    <td> <h3><a href="/deletecam.php?id= <?php echo urlencode($row['id']); ?> "> Delete </a>  </h3></td></tr> 

    <?php
            }

    echo "</table>";
?>
于 2013-02-04T18:52:35.810 回答
1

将其更改为:

while ($row = mysql_fetch_array($result)) {
    echo "<tr>
    <td>" . $row['id'] . "</td>
    <td>" . $row['name'] . "</td>
    <td>" . $row['model'] . "</td>
    <td>" . $row['ipaddress'] . "</td>
    <td>" . $row['url'] . "</td>
    <td>" . $row['port'] . "</td>      
    <td> <h3> <a href='/deletecam.php?id=" . urlencode($row['id']) . "'> Delete </a> </h3> </td></tr>"; 
}

你不应该<html>在桌子里面。而且您不能<?php在回显字符串中使用。

于 2013-02-04T19:20:08.023 回答