dongqi3533 2016-10-19 01:05
浏览 43
已采纳

无法使用php表单回显

My PHP form seems to be operating fine. The page comes up and when I click on the submit button, the isset($_POST['submitted']) condition at the start is hit and the code run.

The only issue is that I have a couple of echo lines in the code to produce a JS alert box. Neither seem to be getting called. I'm not sure that the external PHP functions are being called either as I have no way of testing the value returned.

My PHP looks like this

<?php if (isset($_POST['submitted'])) {
$output = checkData(); 
if ($output != "done")
{
    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" action="">
...
<input type="submit" name="submitted" value="Create Meeting">
</form>
<?php 
} 
?>

My checkData() function simply checks to see if the other parts of the form data are empty and exit with either "done" (no errors) or a message if one of the form elements is empty.

createMeeting() will create a meeting based on the data and submit it to my server - currently, it takes the same data as checkData() and then returns.

Both functions come back with no errors when I run it through an online PHP code checker.

  • 写回答

3条回答 默认 最新

  • dongsheng4126335 2016-10-19 01:22
    关注

    I've tried your code and it seems to work fine in my case.

    <?php if (isset($_POST['submitted'])) {
    $output = "done"; //even if this line is not equal to 'done', the code still works fine
    if ($output != "done")
    {
        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" action="">
        ...
        <input type="submit" name="submitted" value="Create Meeting">
        </form>
    <?php
    }
    ?>
    

    So to my knowledge, there're errors with your createMeeting() or checkData() functions. Can you please be more specific with the error messages (if any)?

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题