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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度