Page 1 of 1

PHP parse error, my form, not CMSMS

Posted: Tue Mar 27, 2007 5:03 pm
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

Re: PHP parse error, my form, not CMSMS

Posted: Tue Mar 27, 2007 6:03 pm
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


   

Re: PHP parse error, my form, not CMSMS

Posted: Tue Mar 27, 2007 6:20 pm
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:






Re: PHP parse error, my form, not CMSMS

Posted: Tue Mar 27, 2007 7:37 pm
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

Re: PHP parse error, my form, not CMSMS

Posted: Mon May 07, 2007 9:27 pm
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";

Re: PHP parse error, my form, not CMSMS

Posted: Mon May 07, 2007 9:31 pm
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

Re: PHP parse error, my form, not CMSMS

Posted: Sat Feb 28, 2009 3:47 pm
by replytomk3