doushua7737 2013-01-05 09:17
浏览 19
已采纳

如果表单POST为空,如何阻止php执行脚本?

I have two input fields and whenever I open my page, it displays errors since at the start user has not entered any input to any of the field (& the errors are displayed because the user input is used in sql queries to retrieve data). I just want to display those two forms at start of the page not the errors. Both inputs are required to execute the Compare button. If user has not entered either one of the inputs it should not send request to php for scripting. I mean the Compare button should send request only if both inputs are filled otherwise it should give a message to user to Type the required fields. How to do this?

$trimUser= trim ($_POST['name']);
if(empty($name) || empty($name2))
{
echo "Enter a name ";
}
else if (isset($_POST['name']))
{   
$name=$_POST['name'];
}
else if (isset($_POST['name2']))
{
$name2=$_POST['name2'];
}

& here is my form:

<form action="index.php" method="POST">
<input class="span3 search-query" placeholder="Type User A" type="text" name="name" id="field"/
<input class="span3 search-query" placeholder="Type User B"  name="name2" type="text"
id="field2"/>
<button class="btn btn-primary" data-loading-text="Loading..." >Compare</button>
  • 写回答

7条回答 默认 最新

  • dqmchw0071 2013-01-05 13:03
    关注

    I simply got rid all of all the errors by adding this error_reporting(E_ERROR | E_PARSE); at the start of my code. However if anyone want to check display validation error messages , one can do easily by what others have mentioned . i.e By using if($_Post). Anyway ,Thank you everyone for the help.

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料