PHP: id号被剪掉,只保留第一个数字


PHP: the id number is cut out, and remain only the first number

我正在制作一个小CMS。我目前正在编辑页面。它可以正常工作,但只有当页面的"id"小于10(只有1个数字)

这是发送到edit_page的链接,该表单预先填充了适当的内容:

<a href="edit_page.php?nav_id_trough_link=<?php echo urlencode($selected_nav['id']); ?>">Edit this page</a> </p>

(抱歉nav_id_trough_link的名字很笨拙,只是我正在学习)

当我刚刚访问这个页面时,在地址栏中有这个:

http://localhost:8080/test1again/backend.php?navv=39

但是当我点击编辑链接,把我带到edit_page.php,在地址栏出现这个:

http://localhost:8080/test1again/edit_page.php?nav_id_trough_link=3

不知怎么的,它把9剪掉了如果页面的id为40,也会发生同样的情况,那么将变为4(并使用id为4..的页面的内容预填充表单)

有人知道为什么会发生这种情况吗?

错误明显在于:

<?php echo urlencode($selected_nav['id']); ?>

你确定$selected_nav是一个数组吗?它看起来像$selected_nav是一个字符串,你正在访问它像一个数组,因为字符串可以作为数组访问,但只使用数字索引,'id'被转换为int (0)和第一个字符返回。