aebstract Posted June 7, 2006 Share Posted June 7, 2006 I have a contact form that when fully filled out returns an "Error:" message at top of my forum, though has no errors in it. I have it set up so that if there is an error, it says "Error:" then it will list the various errors in the form. When the entire form is filled out correctly, it says error without any errors listed! Here is my script, and a link to the form:[a href=\"http://carbenco.com/index.php?menu=contact\" target=\"_blank\"]http://carbenco.com/index.php?menu=contact[/a][code]<?php header("Cache-control: private"); if(isset($sent)) {$content2 .= 'Your message has been sent.';}if(!isset($sent)) {if (isset ($_POST['submit'])) {$problem = FALSE;if ($problem = TRUE) {$content2 .= 'Errors:<br />';}$_POST['firstname'] = strip_tags($_POST['firstname']);$_POST['lastname'] = strip_tags($_POST['lastname']);if (empty ($_POST['firstname'])) {$problem = TRUE;$content2 .= 'Your first name is required<br />';}if (empty ($_POST['lastname'])) {$problem = TRUE;$content2 .= 'Your last name is required.<br />';}if (empty ($_POST['email1'])) {$problem = TRUE;$content2 .= 'Email Address is a required field.<br />';}elseif (!preg_match("/.*@.*..*/", $_POST['email1']) OR preg_match("/(<|>)/", $_POST['email1'])){$problem = TRUE;$content2 .= 'The email address you chose was incorrect.<br />';}if (empty ($_POST['subject'])) {$problem = TRUE;$content2 .= 'You are required to enter a subject.<br />';}if (empty ($_POST['body'])) {$problem = TRUE;$content2 .= 'You are required to submit a message.<br />';}if (!$problem) {$firstname = $_POST['firstname'];$lastname = $_POST['lastname'];$email = $_POST['email1'];$body = $_POST['body'];$subject = $_POST['subject'];$sendmail = "$firstname $lastname$email$body";$sendmail2 = "Hi $firstname $lastname,This is an automatic message sent to confirm that your following message has been sent in to carbenco:$body";mail ('aebstract@gmail.com', 'Contact: Carbenco', $sendmail, 'From: aebstract@gmail.com');mail ('$email', 'Contact: Carbenco', $sendmail2, 'From: $email');header ("Location: index.php?menu=contact&sent");} else {}}$content2 .= '<form action="index.php?menu=contact" method="post">Contact Form<br /><br />First Name: <br /><input type="text" class="textfield" name="firstname" maxlength="20" size="20" value="' . $_POST['firstname'] . '" /><br />Last Name: <br /><input type="text" class="textfield" name="lastname" maxlength="20" size="20" value="' . $_POST['lastname'] . '" /><br />Email Address: <br /><input type="text" maxlength="32" class="textfield" name="email1" size="20" value="' . $_POST['email1'] . '" /><br /><br />Subject: <br /><input type="text" class="textfield" name="subject" maxlength="20" size="20" value="' . $_POST['subject'] . '" /><br />Message: <br /><textarea name="body" rows="5" cols="40" class="textfieldmsg"></textarea><br /><br /><input type="submit" name="submit" value="Send" class="textfield" /></form>';}?>[/code]Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11420-mail/ Share on other sites More sharing options...
redarrow Posted June 7, 2006 Share Posted June 7, 2006 try adding these on false and true " "; Quote Link to comment https://forums.phpfreaks.com/topic/11420-mail/#findComment-42849 Share on other sites More sharing options...
kenrbnsn Posted June 7, 2006 Share Posted June 7, 2006 The conditional operator that tests for equality is "==", not "=" which is the assignment operator.Your code:[code]<?php if ($problem = TRUE) ?>[/code]says ... assign the value TRUE to $problem. Since this succeeds, the "if" suceeds.Change your code to [code]<?php if ($problem === TRUE) ?>[/code] which will only succeed if the value of $problem is the boolean TRUE.Ken Quote Link to comment https://forums.phpfreaks.com/topic/11420-mail/#findComment-42850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.