lialight Posted January 8, 2007 Share Posted January 8, 2007 I am not sure where I am going wrong here... I have had two other people look at my code an they said it looked fine and they had no idea what is wrong with it.... please someone help me! The part I am having trouble with is that there is an email field and a phone field and the user is required to enter either the phone or the e-mail but they do not have to enter both. [code]<?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "HH1"; $name_field = $_POST['visitor']; $email_field = $_POST['visitormail']; $City = $_POST['City'];$State = $_POST['State'];$Zip = $_POST['Zip'];$MemberID = $_POST['MemberID'];$MiddleInitial = $_POST['MiddleInitial'];$MemberAddress = $_POST['MemberAddress'];$MemberAddress2 = $_POST['MemberAddress2'];$MemberPhone = $_POST['MemberPhone'];$DoctorFirstName = $_POST['DoctorFirstName'];$DoctorLastName = $_POST['DoctorLastName'];$DoctorAddress = $_POST['DoctorAddress'];$DoctorAddress2 = $_POST['DoctorAddress2'];$DoctorCity = $_POST['DoctorCity'];$DoctorState = $_POST['DoctorState'];$DoctorZip = $_POST['DoctorZip'];$DoctorAddress = $_POST['DoctorAddress'] ;$DoctorAddress2 = $_POST['DoctorAddress2'] ;$HealthPlan = $_POST['HealthPlan'];$radio = $_POST['radio'];}if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) {echo "<h2>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\n";echo $badinput;}if(empty($visitor) && empty($visitormail)) {echo "Use Back fill in e-mail or phone #\n";}if(empty($visitor)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">First Name</font></b>\n";}if(empty($LastName)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Last Name</font></b>\n"; }if(empty($MemberID)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member ID</font></b>\n";}if(empty($MemberAddress)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member Address.</font></b>\n";}if(empty($City)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member City.</font></b><br><br>\n";}if(empty($State)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Member State.</font></b><br><br>\n";}if(empty($DoctorFirstName)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor First Name.</font></b><br><br>\n"; echo "<br><br>";}if(empty($DoctorLastName)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor Last Name.</font></b><br><br>\n";}if(empty($DoctorAddress)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor Address.</font></b><br><br>\n"; echo "<br><br>";}if(empty($DoctorCity)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor City.</font></b><br><br>\n";}if(empty($DoctorState)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Doctor State.</font></b><br><br>\n";}if(empty($HealthPlan)) { echo "<b>Please GO BACK and fill in the required field <font color=\"red\">Health Plan.</font></b><br><br>\n";}$message = " Member Name: $visitor \nLast Name: $LastName \nMiddle initial: $MiddleInitial \nMemberID: $MemberID \nCity: $City \nState: $State \nZip: $Zip \nAddress: $MemberAddress \nAddress2: $MemberAddress2 \nPhone: $MemberPhone \nEmail: $visitormail \nAre they a member?: $radio \nNon member name: $NonMemberName \nNon member relationship: $NonMemberRelationship \n Doctor First Name: $DoctorFirstName \nLast Name: $DoctorLastName \nAddress: $DoctorAddress \nAddress2: $DoctorAddress2 \nCity: $DoctorCity \nZip: $DoctorZip \nState: $DoctorState \nAddress: $DoctorAddress \nAddress2: $DoctorAddress2 \nHealth Plan: $HealthPlan \n";$from = "From: [email protected]\r\n";mail("[email protected]", $subject, $message, $from);?>[/code] Link to comment https://forums.phpfreaks.com/topic/33302-contact-form-if-statement-please-help/ Share on other sites More sharing options...
emehrkay Posted January 8, 2007 Share Posted January 8, 2007 first id say stop using empty becuase spaces return as not empty. use trim($var) != "" if(trim($email) == '' && trim($phone) == ''){echo 'enter phone or emiail';} Link to comment https://forums.phpfreaks.com/topic/33302-contact-form-if-statement-please-help/#findComment-155564 Share on other sites More sharing options...
cshireman Posted January 8, 2007 Share Posted January 8, 2007 I agree with emehrkay, you need to sanitize your data, but you also need to set your variables properly. I noticed that you are testing variables that have not been set.[code]if(![b]$visitormail[/b] == "" && (!strstr([b]$visitormail[/b],"@") || !strstr([b]$visitormail[/b],"."))) .....if(empty([b]$visitor[/b]) && empty([b]$visitormail[/b])) {.....if(empty([b]$visitor[/b])) {[/code]Those values will only work if you have register_globals set in your php.ini file, which is bad practice for any piece of production code. Try inserting the following code just before you test your variables.[code]$visitor = $_POST['visitor']; $visitormail = $_POST['visitormail'];[/code] Link to comment https://forums.phpfreaks.com/topic/33302-contact-form-if-statement-please-help/#findComment-155601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.