Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Is my logic wrong for this form??

Posted on 2011-10-22
1
Medium Priority
?
131 Views
Last Modified: 2012-06-21
Upon landing on this page, there should be no value for 'send'.  I thought my form should only allow the part that says 'if send=2, then do this', should only appear if the value for send is 2 (which it would only be if the form was not filled out entirely), but it is also appearing if send has no value.

Any ideas??
<?php include ("header_contact.php") ?>	
	
				</td>
    			<td width="550" valign="top">
					<table width="95%" border="0" cellspacing="0" cellpadding="3" class="maintext" align="center">
  						<tr>
    						<td valign="top"> <div id="main" /><h1>Contact</h1><br /><br />
							
							

							<br /><br />All required fields on this page are designated by an <font color="red">*</font>.<br />
						
						<?PHP if ($_GET[send] < 1) { ?>
						<?PHP echo $_GET[send];?>
<?php include "appformdd.php";?>


							</td>
  						</tr>
					</table>

				</td>
    			
  			</tr>
		</table>
	</td>
    <td width="5" bgcolor="#FF5903">
	</td>
	</tr>
</table>
<?php include ("footer.php") ?>


<?PHP } 
if ($_GET[send] == 1) 

include ("securimage/securimage.php");

$securimage = new Securimage();

{
        if ($_POST[NAME] == $nil || $_POST[COMPANY] == $nil || $_POST[PHONE] == $nil || $_POST[EMAIL] == $nil || $securimage->check($_POST['captcha_code']) == false)
$_GET[send] = 2;

}

if ($_GET[send] == 1) {

//$to="info@domain.com";
$to="john@domain.com";
$headers.= "MIME-Version: 1.0\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\n";
$headers.= "From: Contact Form <info@domain.com>\r\n"; 
$subject = "Contact Request - Online Form";

$body = "<HTML><BODY>
<b>Name:</b> $_POST[NAME]<br />
<b>Company:</b> $_POST[COMPANY]<br />
<b>Phone:</b> $_POST[PHONE]<br />
<b>Email:</b> $_POST[EMAIL]<br />
<b>Contact Method:</b> $_POST[CONTACTMETHOD]<br />
<b>Reason for Request:</b> $_POST[COMMENT]<br />

</BODY></HTML>
";

mail($to,$subject,$body,$headers);

?>
<center><h3>&nbsp;Your request has been submitted!</h3><br />
A company representative will contact you as soon as possible. Thank you.<br /><br /></center>


<?PHP } 
if ($_GET[send] == 2) {
?>
<br /><center><font color="red">Please complete all the required fields.  Required fields are marked with an *.</font>
</center>
<BR>
<?php include "appformdd.php"; ?>





							</td>
  						</tr>
					</table>

				</td>
    			
  			</tr>
		</table>
	</td>
    <td width="5" bgcolor="#FF5903">
	</td>
	</tr>
</table>
<?php include ("footer.php"); } ?>

Open in new window

0
Comment
Question by:tru504187211
1 Comment
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 37012682
Two important things about your code.

#1: Array keys should be quoted or they may be mistaken for constants.  $_GET[send] should be $_GET["send"].  All the rest like $_POST[NAME] should be changed also.  See Array do's and don'ts on this page http://us2.php.net/manual/en/language.types.array.php

#2: Since PHP is a loosely typed language, sometimes you need to be aware of what it 'thinks' you're doing.  All data from a POST or GET comes in as Text.  Text needs to be quoted while numbers are not.  Your comparison if ($_GET[send] < 1) isnt' working because PHP sees the character '1' in $_GET[send] which is a number value of 49 which is obviously much larger than the number 1 in your code.  Your comparison might work if you wrote if ($_GET["send"] < "1") which will compare the value to the character '1', not the number 1 as you currently have.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question