Unexpected T_Variable????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
willyjlyles
Forum Newbie
Posts: 5
Joined: Mon Apr 02, 2007 9:56 am

Unexpected T_Variable????

Post by willyjlyles »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to write a script that will email both the user and the site owner when a user registers on the site.  Everytime I click submit on the form, it tells me:

[quote]Parse error: syntax error, unexpected T_VARIABLE in /misc/27/000/115/947/6/user/web/incomegains.bravehost.com/IGcreate.php on line 9[/quote]

The line varies according to how I rearrange the code and stuff.  These are the lines of code that give me trouble:

Code: Select all

$msg = ("Welcome to the Income Gains," . $_POST['FirstName'] . " " . $_POST['LastName'] . "!");
$subject = "Welcome to the Income Gains.";
$MSImsg = "Email: . $_POST['Email']" . "<br>Name: " . $_POST['FirstName'] . " " . $_POS['LastName'] . "<br>Zip: " . $_POST['Zip'] . "<br>Password: " . $_POST['Password'];
$MSIsubj = "New Member"; 

mail("willyjlyles@yahoo.com", $MSIsubj, $MSImsg);
mail($_POST['Email'], $subject, $msg);
I have checked all the $_POST variables to make sure they're correct for the field name. I have tried the $_POST variables with and without the single quotes in the brackets. I have tried both concatenating the strings like above and just making it all one big line of code in quotations. Nothing I can think of works. Why isn't my code working and what to I do to fix it?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_POST['Email'] is giving you the trouble. I'll leave you to try to figure out why before I explain. :)
willyjlyles
Forum Newbie
Posts: 5
Joined: Mon Apr 02, 2007 9:56 am

Post by willyjlyles »

If you're talking about the missing quotation mark, I've tried every combination of quotations and concatenations I can think of and still got the same error, but now I'm off to the books and google to see what's wrong with it.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You got it right on all the other POST variables. Just do the same for this one
willyjlyles
Forum Newbie
Posts: 5
Joined: Mon Apr 02, 2007 9:56 am

Post by willyjlyles »

Okay I have a guess. (I'm in a computer lab right now, and don't have a web server on which to test this)

In all the examples I found, no $_POST variables were in the mail function, which makes me think that I need to set something else equal to $_POST['Email'] and then pass that to the mail function.

Was that it, or am I totally wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Aside from the security implications of using $_POST variables without proper filtration, it's perfectly fine to use them in the data.

Your probably is actually involving the parsing of your strings, not mail().

Have a read through the following page.

http://php.net/language.types.string
willyjlyles
Forum Newbie
Posts: 5
Joined: Mon Apr 02, 2007 9:56 am

Post by willyjlyles »

In that article the only thing I could think of was to enclose the $_POST variables in brackets, so it's {$_POST[Email]}.

There were several ways of creating the string that were listed in the article that I've tried, that should've worked.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're missing something very simple, something that two other posters have pointed out to you...

What is different between how $_POST['Email'] is built into the string as opposed to, say, $_POST['FirstName']?

Code: Select all

$MSImsg = "Email: . $_POST['Email']" . "<br>Name: " . $_POST['FirstName'] . " " . $_POS['LastName'] . "<br>Zip: " . $_POST['Zip'] . "<br>Password: " . $_POST['Password'];
willyjlyles
Forum Newbie
Posts: 5
Joined: Mon Apr 02, 2007 9:56 am

Post by willyjlyles »

Okay, I got it all worked out this time and now it works.

I must've just been repeating a typo or something, because now it's working.

I also see what you mean with making $_POST[Email] like all the rest, but I had tried that (but probably with typos) before and it didn't work.

To fix it all I did was re-type the code SLOWLY, making sure that I remembered to close each parenthesis, bracket, etc.

feyd, you have me intrigued about what you mean by proper filtration. Could you point me somewhere that explains that?

Thanks for all your help.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Search for XSS, SQL Injection, etc. That is what is meant when we talk about filtering input. Taking input and directly echoing it or inserting it into a DB is dangerous to say the least.
Post Reply