(php)我在“get”方法链接中获得了额外的代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(php)我在“get”方法链接中获得了额外的代码相关的知识,希望对你有一定的参考价值。
我的第一个问题溢出:)
我试图创建一个表来显示SQL的所有帖子。我已经完成了下一个代码:
function show_all_posts_in_table(){
global $connection;
$query = "SELECT * FROM posts";
$all_posts_content_query = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($all_posts_content_query)) {
$post_id_display = $row['post_id'];
echo "<tr>";
echo "<td>" . $post_id_display = $row['post_id'] . "</td>";
echo "<td>" . $post_category_display = $row['post_category_id'] . "</td>";
echo "<td>" . $post_title_display = $row['post_title'] . "</td>";
echo "<td>" . $post_author_display = $row['post_author'] . "</td>";
echo "<td>" . $post_date_display = $row['post_date'] . "</td>";
$post_image_display = $row['post_image'];
echo "<td>" . "<img src= '../images/{$post_image_display}' width='200' height='auto'>" . "</td>";
echo "<td>" . $post_content_display = $row['post_content'] . "</td>";
echo "<td>" . $post_tags_display = $row['post_tags'] . "</td>";
echo "<td>" . $post_status_display = $row['post_status'] . "</td>";
echo "<td>{$post_id_display}</td>";
echo "<td> <a href='posts.php?delete={$post_id_display}'>DELETE</a> </td>";
echo "</tr>";
}
}
我看到我制作的桌子上的所有帖子,一切正常。
问题是当我尝试删除其中一个帖子时(用“get”方法删除href)。
出于某种原因,我无法理解,在chrome的地址行上我得到了额外的</td>
。
我被引导到:posts.php?delete=6</td>
。
任何人都能理解为什么会这样吗?
谢谢!
答案
$post_id_display = $row['post_id'] . "</td>";
将$post_id_display
设置为$row['post_id']
,然后将</td>
连接到它。
无需将这些值存储在单独的变量中。只需直接使用$row
数组即可。
将其更改为:
while ($row = mysqli_fetch_assoc($all_posts_content_query)) {
echo "<tr>";
echo "<td>" . $row['post_id'] . "</td>";
echo "<td>" . $row['post_category_id'] . "</td>";
echo "<td>" . $row['post_title'] . "</td>";
echo "<td>" . $row['post_author'] . "</td>";
echo "<td>" . $row['post_date'] . "</td>";
echo "<td>" . "<img src= '../images/" . $row['post_image'] . "' width='200' height='auto'>" . "</td>";
echo "<td>" . $row['post_content'] . "</td>";
echo "<td>" . $row['post_tags'] . "</td>";
echo "<td>" . $row['post_status'] . "</td>";
echo "<td>" . $row['post_id'] . "</td>";
echo "<td> <a href='posts.php?delete=" . $row['post_id'] . "'>DELETE</a> </td>";
echo "</tr>";
......它应该有效。
另一答案
作为@MagnusEriksson的答案的扩展只是对正在发生的事情的一点测试/简化:
你现在做了什么:
$a = "A";
$b = "B";
echo "x" . $a = $b . "y"; // -> xBy
echo " value of A: ".$a; // -> value of A: By
这可行:
$a = "A";
$b = "B";
echo "x" . ($a = $b) . "y"; // -> xBy
echo " value of A: ".$a; // -> value of A: B
以上是关于(php)我在“get”方法链接中获得了额外的代码的主要内容,如果未能解决你的问题,请参考以下文章
我在 ios 6 中获得了用于 Facebook 的格式错误的访问令牌