dourukeng5302 2014-07-29 13:13
浏览 79
已采纳

在表单提交之前定义$ _POST变量[重复]

This question already has an answer here:

How can I define my $_POST variables in below sample code before submission to prevent PHP Undefined index notice. HTML sample code:

<form action="" method="post">
<input type="text" name="my_input" id="my_input">
<button type="submit">Submit</button>
</form>

my php sample code:

$post_variable = $_POST["my_input"];

Thanks in advance.

</div>
  • 写回答

2条回答 默认 最新

  • donglin8467 2014-07-29 13:15
    关注

    just check that the post variable exists before trying to access it:

    $value1 = isset($_POST["my_input"]) ? $_POST['my_input'] : false;
    

    now, if my_input is set in the post $value1 will contain it, otherwise it will be false

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部