PHP parse error, my form, not CMSMS

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
izzysanime

PHP parse error, my form, not CMSMS

Post by izzysanime »

Hey, I m making a form thing here, and this is the error i get


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /mounted-storage/home8/sub002/sc15160-KJJA/www/jo/admin.php on line 18

Line 18 -      ."else if(($_POST['user'] == \"$user\") && ($_POST['pass'] == \"$pass\")) header(\"Location: \"$location\"\");\n";

its for saving the info to form

$NewText =      "\n"
                ."else if(($_POST['user'] == \"$user\") && ($_POST['pass'] == \"$pass\")) header(\"Location: \"$location\"\");\n";

thanks

Josh
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: PHP parse error, my form, not CMSMS

Post by calguy1000 »

if you're testing for the exact string $user then your expression should be:

else if( $_POST['user'] == '$user' ...

if you are comparing the value of $_POST['user'] with the $user variable name then your expression should be:

elseif( $_POST['user'] == $user ...

if you are comparing the value of $_POST['user'] with the $user variable name, but there are some quotes in $_POST['user'] that are not in $user you should use something like:

elseif( $_POST['user'] == "\"$user\"" ...

Here's tip #1 .... break things up to multiple lines  so that PHP can tell you better exactly where your problem is
          tip $2 .... use lots of brackets


   
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
izzysanime

Re: PHP parse error, my form, not CMSMS

Post by izzysanime »

well, maybe i should explain more, their are 2 php files involved.  One page is the login.php info and one is the admin.php page to setup the login info for that login.php file.  I hope that makes sense ^_^.  All that line 18 is doing is placing the submited form info onto that login.php file. 

I was hoping that there would just be a simple error involved. 

Admin code:




Login.php





Log In







Please Log In Below:
" method="post">
Username:
Password:





izzysanime

Re: PHP parse error, my form, not CMSMS

Post by izzysanime »

OK, i think i can make this make sense. 

How do i get PHP to place a "line of php code" into another php page literally but also change my variables that i have setup from the form (ie:  $user, $pass)?

Thanks
Josh
Kayin
Forum Members
Forum Members
Posts: 59
Joined: Mon Jun 05, 2006 2:33 am

Re: PHP parse error, my form, not CMSMS

Post by Kayin »

You need to escape the $ in your $_POST variables

I just tested this line and this parsed correctly:

$NewText = "\n else if((\$_POST['user'] == \"$user\") && (\$_POST['pass'] == \"$pass\")) header(\"Location: \"$location\"\");\n";
Kayin
Forum Members
Forum Members
Posts: 59
Joined: Mon Jun 05, 2006 2:33 am

Re: PHP parse error, my form, not CMSMS

Post by Kayin »

the php parser basically just tries to fill your variables into the string. You want the literal string $_POST['pass'] == $pass.

So... escape every $ in it, making:

$NewText = "\n else if((\$_POST['user'] == \"\$user\") && (\$_POST['pass'] == \"\$pass\")) header(\"Location: \"\$location\"\");\n";


It's just backslash crazy.  Sorry if I didn't explain that very well. I'm terrible at explaining things.

-E
Post Reply

Return to “The Lounge”