dongyang7152 2016-11-15 17:03
浏览 39
已采纳

PHP,MySQL - 如何正确地将变量传递给链接[重复]

This question already has an answer here:

So what I have is:

$id = $_POST['id'];
$loann = $_POST['loann'];
$dater = $_POST['dater'];
$apaid = $_POST['apaid'];

... and:

$result = mysql_query("UPDATE _loan SET loana='$loann', dater = CONCAT_WS(',', dater,  '$dater' ), apaid = CONCAT_WS(',', apaid , '$apaid' ) WHERE id=$id");

    echo $id;

Everything works fine now the problem shows when I tray to pass the value of $id into:

echo ('<meta http-equiv="refresh" content="1;url=view_details.php?id=$id">');

What I would get in the browser would be:

mysite.net/view_details.php?id=$id

Instead of:

mysite.net/view_details.php?id=133

Any help is greatly appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • dongyanpai2701 2016-11-15 17:06
    关注

    You're using a single-quoted string, which doesn't expand variables. Either use a double-quoted string:

    "<meta http-equiv=\"refresh\" content=\"1;url=view_details.php?id=$id\">"
    

    or concatenate the strings:

    '<meta http-equiv="refresh" content="1;url=view_details.php?id=' . $id . '">'
    

    Side note: Your code is vulnerable to SQL injection. You should start reading here and here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题