Is my logic wrong for this form??

Posted on 2011-10-22
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 width="550" valign="top">
					<table width="95%" border="0" cellspacing="0" cellpadding="3" class="maintext" align="center">
    						<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 width="5" bgcolor="#FF5903">
<?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) {

$headers.= "MIME-Version: 1.0\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\n";
$headers.= "From: Contact Form <>\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 />



<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>
<?php include "appformdd.php"; ?>


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

Open in new window

Question by:tru504187211
    1 Comment
    LVL 82

    Accepted Solution

    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

    #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.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now