Jump to content


Photo

PHP Trouble


  • Please log in to reply
5 replies to this topic

#1 npsken

npsken

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:Computer Programming<br />Graphic Design

Posted 20 July 2007 - 03:46 PM

I am getting the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/.barton/kenxpowerz/game2life.com/phpbbint.php on line 37


This is the code:
<?phpif (!defined('IN_SITE')) {	die('HACKING ATTEMPT');}// phpbb3 login, user session management$phpbb_root_path = './forum/';$returnAddress = '../index.php';// include phpbb stuffdefine('IN_PHPBB', true);$phpEx = substr(strrchr(__FILE__, '.'), 1);include($phpbb_root_path . 'common.' . $phpEx);include($phpbb_root_path . 'includes/functions_display.' . $phpEx);// start phpbb3 session management$user->session_begin();$auth->acl($user->data);// start main page stuffif (!$user->data['is_registered']) {?><div id="login">	<form method="post" action="<? echo $phpbb_root_path' ?>ucp.php?mode=login">		<ul>			<li><label for="username">Username:</label> <input type="text" name="username" id="username" size="5" title="Username" /></li><br />			<li><label for="password">Password:</label> <input type="password" name="password" id="password" size="5" title="Password" /></li><br />			<li><label for="autologin">Log me on automatically each visit:</label> <input type="checkbox" name="autologin" id="autologin" /></li><br />			<li><input type="submit" name="login" value="Login" /></li><br />		</ul>		<input type="hidden" name="redirect" value="<? echo $returnAddress; ?>" />	</form></div><?} else {?>Hi <? echo $user->data['username']; ?>! <a href="<? echo $phpbb_root_path; ?>ucp.php?mode=logout&redirect=<? echo $returnAddress; ?>&sid=<? echo $user->data['session_id']; ?>">Logout</a><br /><?vardump($user->data);}?>

According to notepad++, the line that says "Hi username!" is line 37.

Can somebody please tell me what is going on?

#2 dEcade

dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 20 July 2007 - 06:16 PM

echo $phpbb_root_path' needs to have a ; instead of '

replace

<form method="post" action="<? echo $phpbb_root_path' ?>ucp.php?mode=login">

with

<form method="post" action="<? echo $phpbb_root_path; ?>ucp.php?mode=login">

Edited by dEcade, 20 July 2007 - 06:18 PM.


#3 pirateXcore

pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 20 July 2007 - 06:34 PM

<form method="post" action="<? echo '$phpbb_root_path'; ?>ucp.php?mode=login">

Wouldn't that be a little bit "better" coding practice?
or even
<?
echo"<form method='post' action='$phpbb_root_path ucp.php?mode=login'>";
?>
That would probably get some kind of error I think, with the ...path ucp...maybe if you broke it up or something idk....like
echo"<form method='post' action='".."$phpbb_root_path".."ucp.php?mode=login'>";
lol what am I talking about, who knows!

#4 dEcade

dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 20 July 2007 - 07:36 PM

<form method="post" action="<? echo '$phpbb_root_path'; ?>ucp.php?mode=login">

Wouldn't that be a little bit "better" coding practice?
or even
<?
echo"<form method='post' action='$phpbb_root_path ucp.php?mode=login'>";
?>
That would probably get some kind of error I think, with the ...path ucp...maybe if you broke it up or something idk....like
echo"<form method='post' action='".."$phpbb_root_path".."ucp.php?mode=login'>";
lol what am I talking about, who knows!


No, php won't echo the variable if you have '' around it. If you use "" It will work. (The second way would work.)

for example:

if I had:
<?php
$test	=	'test';

echo '$test';
?>

If I went to that page it would just say $test instead of what the variable is equal to.

if you did it like this, on the other hand, it would work:

<?php
$test	=	'test';

echo "$test";
?>

It also works with out anything around it. Thats the way I prefer.

<?php
$test	=	'test';

echo $test;
?>

Then if you have non-variable stuff you just do $test .'What ever...';

The way he has done it works just fine.

I recommend starting it with <?php instead of <? though. But thats really up to him.

dEcade

Edited by dEcade, 20 July 2007 - 07:38 PM.


#5 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 20 July 2007 - 07:38 PM

<form method="post" action="<? echo '$phpbb_root_path'; ?>ucp.php?mode=login">

Wouldn't that be a little bit "better" coding practice?
or even
<?
echo"<form method='post' action='$phpbb_root_path ucp.php?mode=login'>";
?>
That would probably get some kind of error I think, with the ...path ucp...maybe if you broke it up or something idk....like
echo"<form method='post' action='".."$phpbb_root_path".."ucp.php?mode=login'>";
lol what am I talking about, who knows!


Um... no.

It really doesn't matter, and comes down to a preference of the coder.
I personally either use double-quotes and encapsulate variables with curly brackets (like you technically are supposed to do, as to separate it from other words that may become 'part of the variable name'), or use single quotes and separate with periods when I'm using alot of functions/methods and constants.

Your other method, 'echo"<form method='post' action='".."$phpbb_root_path".."ucp.php?mode=login'>";', won't work... You will have a parse error because of the '..' and having nothing in between, and you will get an unexpected string error from the variable not being connected by a period.
The correct method of what you are implying would be as follows:

echo '<form method="post" action="'.$phpbb_root_path.'ucp.php?mode=login">';

No point in using double quotes if you are not placing variables directly in them anyways...

#6 pirateXcore

pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 20 July 2007 - 08:07 PM

Okay, hopefully I didn't confuse them then!
I was just trying to think of how everyone always tells me things SHOULD be coded, if we all spent the time to make it pretty and neat.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users