douyun3887 2017-02-09 17:19
浏览 83

PHP脚本因Isset()而死。 其他选择?

I have a contact form I'm trying to run, but for whatever reason the script will die every time I attempt to submit it. Not sure why. Is there anything blantanly wrong with the code below? I wasn't using isset() before, but someone here suggested I do and now it breaks the page.

FORM

            <form class="contactform" method="post" action="php/contact.php">
                <h3>Name</h3>
                <input class="form inputboxes" type="text" name="name">
                <h3>Email</h3>
                <input class="form inputboxes" type="email" name="email">
                <h3>Phone</h3>
                <input class="form inputboxes" type="number" name="phone">
                <h3>Message</h3>
                <textarea class="form inputboxes" name="message"></textarea>
                <h3 class="captchastyle">Are you real? What is 2 + 2?</h3><input class="captcha captchastyle" type="text" name="captcha" maxlength="1">
                <input class="form submit" name="submit" type="submit" value="Submit">
            </form>

PHP

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $captcha = $_POST['captcha'];
    $from = 'From: HankSmith.com Contact Form'; 
    $to = 'thatbraxjohnsonguy@gmail.com'; 
    $subject = 'HANK SMITH CONTACT FORM';

    $body = "
            From: $name
 
            E-Mail: $email
 
            Phone: $phone

            Message: $message
";

if (isset($_POST['submit'] && $captcha == 4)) {                
        if (mail ($to, $subject, $body)) { 
        echo '<p style="margin-top: 150; text-align:center; font-size: 18px;">Your message has been sent! Click <a href="../index.php">here</a> to return to the website.</p>';
        }  else {
            echo '<p>Problem sending mail!';
        }
    } else { 
        echo '<p>Something went wrong, try again later!</p>'; 
    }
?>

ERROR_LOG

[09-Feb-2017 12:15:46 America/New_York] PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /home/yourerlv/public_html/hanksmith.com/php/contact.php on line 17

  • 写回答

2条回答 默认 最新

  • doudan5136 2017-02-09 17:21
    关注

    You're doing it wrong. You need to move the parenthesis over so it's only evaluating the one variable:

    if (isset($_POST['submit']) && $captcha == 4) { 
                              ^
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?