Jump to content


Photo

T_Variable... Wanting to understand more...


  • Please log in to reply
4 replies to this topic

#1 titangf

titangf
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationColorado, USA

Posted 04 April 2006 - 08:30 PM

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.

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

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*/

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
[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--][a href="http://www.csszengarden.com/" target="_blank"]css zen garden - beautiful design with the programmer in mind[/a][!--colorc--][/span][!--/colorc--]

[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--]Time is the invention of man to gauge what his achievements have been before he fades to dust.[!--colorc--][/span][!--/colorc--]

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 04 April 2006 - 09:12 PM

see this line?

            ."Inquiring About: ".$inquiring."\n"

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.

edit: 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
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 titangf

titangf
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationColorado, USA

Posted 05 April 2006 - 03:59 PM

Woot!.... Thanks redbullmarky, yep that fixed it all. Thanks.

I think that answered all my questions...
[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--][a href="http://www.csszengarden.com/" target="_blank"]css zen garden - beautiful design with the programmer in mind[/a][!--colorc--][/span][!--/colorc--]

[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--]Time is the invention of man to gauge what his achievements have been before he fades to dust.[!--colorc--][/span][!--/colorc--]

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 April 2006 - 05:24 PM

I would recommend you to rethink the way you use if/else statements, see the code below:
if($firstName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
            }
You can chnage that to this:
if(!$firstName) {
    $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input
}
Use the Not 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.

#5 titangf

titangf
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationColorado, USA

Posted 05 April 2006 - 05:29 PM

Ah.... great point... and more streamlined... thanks wildteen
[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--][a href="http://www.csszengarden.com/" target="_blank"]css zen garden - beautiful design with the programmer in mind[/a][!--colorc--][/span][!--/colorc--]

[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--]Time is the invention of man to gauge what his achievements have been before he fades to dust.[!--colorc--][/span][!--/colorc--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users