doujindou4356
2016-10-19 00:32
浏览 39
已采纳

提交按钮没有按下isset()调用

I have a PHP form set like this

<?php if (isset($submitted)) {
$output = checkData(); 
if (!is_null($output))
{
    echo '<script type="text/javascript">alert("' . $output . '"); </script>';
}
else 
{
    createMeeting();
    echo '<script type="text/javascript">alert("You meeting has been created. All of the recipients should shortly receive an email"); </script>';
    header('Location: index.php');
}   
} else { ?>
<center>
<form method="POST">
...
<input type="submit" name="submitted" value="Create Meeting">
</form>
<?php 
} 
?>

When I run it through a PHP code checker (codechecker website), no errors are returned. However, when I click on the submit button, the isset($submitted) code never seems to be executed (I've tested this by adding some echo statements in that section of the code).

If I click on the submit button, the form is cleared, so something is happening. I've put a number of different actions in, but the code is still not hit.

图片转代码服务由CSDN问答提供 功能建议

我有一个像这样的PHP表单

 &lt;  ?php if(isset($ submitted)){
 $ output = checkData();  
if(!is_null($ output))
 {
 echo'&lt; script type =“text / javascript”&gt; alert(“'。$ output。'”);  &lt; / script&gt;'; 
} 
else 
 {
 
 
ewMeeting(); 
 echo'&lt; script type =“text / javascript”&gt; alert(“您的会议已创建。所有收件人 应该很快收到一封电子邮件“);  &lt; / script&gt;'; 
 header('Location:index.php'); 
} 
} else {?&gt; 
&lt; center&gt; 
&lt; form method =“POST”&gt; 
。  .. 
&lt; input type =“submit”name =“submitted”value =“创建会议”&gt; 
&lt; / form&gt; 
&lt;?php 
} 
?&gt; 
  <  / pre> 
 
 

当我通过PHP代码检查程序( codechecker网站)运行它时,没有错误 回。 但是,当我单击提交按钮时,似乎永远不会执行isset($ submitted)代码(我通过在代码的该部分添加一些echo语句来测试它。) < p>如果我单击提交按钮,表单将被清除,因此发生了一些事情。 我已经添加了许多不同的操作,但代码仍未命中。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doukekui0914 2016-10-19 00:38
    已采纳

    This if (isset($submitted))... should be if (isset($_POST['submitted']))...

    点赞 打赏 评论
  • dream198731 2016-10-19 00:43

    You can check if the form is submitted using:

    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    

    Or check if an individual element of the form has been submitted checking if the name is in the post array using:

    if(isset($_POST['submitted']))
    
    点赞 打赏 评论

相关推荐 更多相似问题