dongying3830 2015-02-02 07:14
浏览 24
已采纳

错误重定向到失败页面

I have a form that takes in a few fields.

Upon entering all fields, email will be sent to me with the details.

If any fields are missing, the form will redirect to fail.html file.

If I select at least one of the select values, I get redirected to the fail.html page.

However, the issue is that if I don't select any of the select multiple dropdown list, I get this error.

Warning: implode() [function.implode]: Invalid arguments passed in /home/mydomain/public_html/iComm/contact.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/iComm/contact.php:6) in /home/mydomain/public_html/iComm/contact.php on line 19

This is the HTML.

 <div id="form">
            <form method="post" action="contact.php">
            <input type="text" name="fullName" placeholder="Full Name">
            <input type="email" name="email" placeholder="Email Address">
            <input type="text" name="number" placeholder="Phone">
            <div class="styled-select">
                <select multiple="multiple" name="choices[]">
                  <option style="color:grey";" value="Fri 8AM">Fri 20 Mar 8PM</option>
                  <option style="color:grey";" value="Sat 8AM">Sat 21 Mar 8AM</option>
                  <option style="color:grey";" value="Sat 2PM">Sat 21 Mar 2PM</option>
                  <option style="color:grey";" value="Sat 8PM">Sat 21 Mar 8PM</option>
                  <option style="color:grey";" value="Sun 8AM">Sun 22 Mar 8AM</option>
                </select>
            </div>
            <input type="submit" class="button" value="Sign Up">
            </form>

This is the PHP file.

    $fullName= $_POST['fullName'];
    $email=$_POST['email'];
    $tel=$_POST['number'];
    $choice = implode(',', $_POST['choices']);

    if(!empty($fullName) && !empty($email) && !empty($tel) && !empty($choice)){
        $to = 'm@gmail.com';
        $subject = '2015';
        $msg = "$fullName is keen to join. His/her email address is $email and number is $tel. He/She chose $choice.";

        mail($to, $subject, $msg, 'From: ' .$email);

        header("Location: success.html");
        }
    else{
        if(empty($fullName) || empty($email) || empty($tel) || empty($choice)){
            header("Location: fail.html");
        }
    }
?>
  • 写回答

3条回答 默认 最新

  • dongzou9047 2015-02-02 07:16
    关注

    Use isset()

    if(isset($_POST['choices'])) {  // This will check if this variable is set or not.
        $choice = implode(',', $_POST['choices']);  
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改