我有一個接觸的形式,我試圖運行,但是由於各種原因,該腳本將每次我試圖提交它死的。不知道爲什麼。下面的代碼有什麼毛病嗎?我之前沒有使用isset(),但這裏有人建議我這樣做,現在它打破了頁面。PHP Script由於Isset()而死亡。其他選項?
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 = '[email protected]';
$subject = 'HANK SMITH CONTACT FORM';
$body = "
From: $name\n
E-Mail: $email\n
Phone: $phone\n
Message: $message\n";
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
你的括號()'測試是錯誤的。它應該是'if(isset($ _ POST ['submit'])&& $ captcha == 4)' – WillardSolutions