dsfds4551 2013-02-04 18:52
浏览 47
已采纳

PHP中的链接回声

You may have seen from my previous questions, I'm brand new to PHP (and coding) and I'm stuck with this.

I've created this code (try not to cringe):

<?php
$result = mysql_query("SELECT `user_id`, `username`, `email` FROM `users` WHERE `approved` = '0' ORDER BY `username`;");

    echo "<table>";
        while($row = mysql_fetch_array($result))
        {
        echo "<tr><td align=center>" . htmlspecialchars($row['username']) . "</td><td> | </td><td align=center>" . htmlspecialchars($row['email']) . " </td><td> | </td><td><a href=\"approve_user.php?phpuser_id=$row['user_id']\"><font color=\"green\">Approve</font></a> | </td><td><a href=\"deny_user.php?user_id=$row['user_id']\"><font color=\"red\">Delete</font></a></td>";
        }
    echo "</table>";
?>

It connects to the database in another file, returns all of the results successfully etc. However, the problems come when I try adding the 'Approve' and 'Delete' links. I want the approve link to go to approve_user.php?user_id=$row['user_id'] and I want the delete link to go to deny_user.php?user_id=$row['user_id'].

I'm getting the error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\liste\approve.php on line 22

Line 22 is the echo in the while loop. I know I've messed up big time on that line somewhere, but for the life of me I can't figure out where. Help is appreciated. Thanks!

  • 写回答

4条回答 默认 最新

  • donglvlao8367 2013-02-04 18:57
    关注

    A quick fix is to concatenate your variables:

    echo "<tr><td align=center>" . htmlspecialchars($row['username']) . "</td><td> | </td><td align=center>" . htmlspecialchars($row['email']) . " </td><td> | </td><td><a href=\"approve_user.php?phpuser_id=" . $row['user_id'] . "\"><font color=\"green\">Approve</font></a> | </td><td><a href=\"deny_user.php?user_id=" . $row['user_id'] . "\"><font color=\"red\">Delete</font></a></td>";
    

    However, the code could benefit from making it more readable or using a template system, or at least consider separating the logic and presentation.


    Side note: The mysql_* library is deprecated, it is recommended to upgrade to PDO or MySQLi.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用