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 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?