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.

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记