Jump to content

T_Variable... Wanting to understand more...


titangf

Recommended Posts

I'm uncertain as to why this doesn't work. I'm getting a T_Variable error. I'm building a contact form that submits the information to a database while emailing the form-ee and the person wanting to recieve this information.

[code]<html>
<head>
</head>
<body>

<?php
/* grabs the POST variables and puts them into variables*/
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];

//---------VALIDATION-------->
    if($firstName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
            }

    if($lastName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input
            }

    if($email){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input
            }

    if($phone){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your phone number<br>\n";//----> ERROR if no input
            }

    if($address){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your mailing address<br>\n";//----> ERROR if no input
            }

    if($city){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input
            }

    if($zipCode){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input
            }
//-------->ERROR FREE??
    if($error==""){
        echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
            ."First Name: ".$firstName."\n"
            ."Last Name: ".$lastName."\n"
            ."Contact me by: ".$company."\n"
            ."E-mail: ".$email."\n\n--------PHONE--------\n"
            ."Phone: ".$phone."\n"
            ."Extension: ".$phoneExt."\n"
            ."Fax: ".$fax."\n"
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
            ."Street Address: ".$address."\n"
            ."City: ".$city."\n"
            ."State: ".$state."\n"
            ."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
            ."Where did you hear about us? ".$heardAbout."\n"
            ."Inquiring About: ".$inquiring."\n"
//----------------------------------
$toAddress="whatever@gmail.com"; /* recieving address this isn't my address, fyi*/
$subject="Customer Inquiry"; /* email subject*/
$recipientSubject="Mountain East Real Estate"; /* recipient's subject */
$receiptMessage = "Thank you ".$firstName." for interest in Mountain East Real Estate.  You will be contacted back within 24 hours to assist with your needs.  If this is submitted on a weekend you will be contacted back on the next buisness day.\n\n\nHere is what you submitted to us:\n\n"
            ."--------CONTACT--------\n"
            ."First Name: ".$firstName."\n"
            ."Last Name: ".$lastName."\n"
            ."Contact me by: ".$company."\n"
            ."E-mail: ".$email."\n\n--------PHONE--------\n"
            ."Phone: ".$phone."\n"
            ."Extension: ".$phoneExt."\n"
            ."Fax: ".$fax."\n"
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
            ."Street Address: ".$address."\n"
            ."City: ".$city."\n"
            ."State: ".$state."\n"
            ."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
            ."Where did you hear about us? ".$heardAbout."\n"
            ."Inquiring About: ".$inquiring."\n"
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;

////////////////////////////////////////  CONNECT TO MYSQL DB  ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("localhost","user", "pass") or die("Unable to connect!"); /* kept general for security purposes */

mysql_select_db("generalContact") or die("Unable to select database!");

//  EXECUTE QUERY --->
$query="INSERT INTO generalContact (
            firstName,
            lastName,
            company,
            email,
            phone,
            phoneExt,
            mobile,
            fax,
            address,
            city,
            state,
            zipCode,
            heardAbout,
            inquiringOn)
        VALUES(
            '".$firstName."',
            '".$lastName."',
            '".$company."',
            '".$email."',
            '".$phone."',
            '".$phoneExt."',
            '".$mobile."',
            '".$fax."',
            '".$address."',
            '".$city."',
            '".$state."',
            '".$zipCode."',
            '".$heardAbout."',
            '".$inquiring."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
    //echo mysql_affected_rows()." row inserted into the database effectively.";

//  CLOSE CONNECTION --->
mysql_close($connection);

///////////////////////////////////////////////////////////////////////////////////
        }
    else{

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n";
            print "$error<br>\n";
            print "<br>\n";
            print "<br>\n";
            print "Please use your \"Back\" button to return to the form.  Thank you.<br>\n";
        }

?>
</body>
</html>
[/code]

[code]Parse error: syntax error, unexpected T_VARIABLE in /home/tornadop/www/www/MountainEast/contact_form.php on line 87

//the following line that is referencing the error is below

$toAddress="whatever@gmail.com"; /* recieving address this isn't my address, fyi*/
[/code]

So I guess my question is three parts.
1) Why am I recieving this error?
2) How can I fix it?
3) And is this something stupid on my part in setting up the coding that I should avoid in the future?

Thanks in advance... guess i need to stop doing late night coding sessions.... lol
Link to comment
Share on other sites

see this line?

[code]
            ."Inquiring About: ".$inquiring."\n"
[/code]

well its the last line in a load of lines that builds up your $mailContent variable, only it's not terminated by a semicolon (;) and tries to run into the next lot of code. add a semicolon at the end of the line i mentioned above and see what you get then.

[b]edit:[/b] infact i noticed you have the above line twice in your code. both are likely to cause problems as both are missing semi colons at the end.

Cheers
Mark
Link to comment
Share on other sites

I would recommend you to rethink the way you use if/else statements, see the code below:
[code]if($firstName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
            }[/code]You can chnage that to this:
[code]if(!$firstName) {
    $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}[/code]Use the [b]Not[/b] comparison operater (!) if you want to check that $firstname is not set. You can change all your if/else statments to the example provided above with the (not) ! operator.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.