/    Sign up×
Community /Pin to ProfileBookmark

Are there any good sites that can check my php code for any errors when I type it in a form and give the correct coding?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 02.2006 — No
Copy linkTweet thisAlerts:
@BOB101authorJun 02.2006 — Man, that bites.

I get a Parse error: parse error, expecting ','' or ';'' on line 85. Why?

[code=php]<?php
$phpbb_root_path = 'forum/';
define ('IN_PHPBB', true);
if (!file_exists($phpbb_root_path . 'extension.inc'))
{
die ('<tt><b>phpBB Fetch All:</b>
$phpbb_root_path is wrong and does not point to your forum.</tt>');
}
include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/stats.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/polls.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/forums.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
init_userprefs($userdata);
if (isset($HTTP_GET_VARS['start']) or isset($HTTP_POST_VARS['start'])) {
$CFG['posts_span_pages_offset'] = isset($HTTP_GET_VARS['start']) ? $HTTP_GET_VARS['start'] : $HTTP_POST_VARS['start'];
}
$new_posts = phpbb_fetch_new_posts();
$poll = phpbb_fetch_poll();
$CFG['posts_trim_topic_number'] = 0;
$CFG['posts_span_pages'] = true;
$news = phpbb_fetch_posts();
phpbb_disconnect();
?>

<!-- LOGIN -->
<?php
if (!$userdata or !$userdata['session_logged_in']) { ?>
<span class="gensmall">
<form action="<?php echo $phpbb_root_path; ?>login.php" method="post" target="_top">
<input type="hidden" class="mainoption" name="redirect" value="<?php echo $PHP_SELF; ?>">
Username:<br>
<input name="username" type="text" class="text" size="20" maxlength="10"><br>
Password:<br>
<input name="password" type="password" class="text" size="20" maxlength="25"><br>
<input type="checkbox" name="autologin"> Remember Login
<div align="center">
<input name="login" type="submit" class="submit" value="Login"> <br>
<a href="<?php echo $phpbb_root_path; ?>profile.php?mode=sendpassword">Forgot password</a> | <a href="<?php echo $phpbb_root_path; ?>profile.php?mode=register">Register</a>
</div>
</form>
</span>
<?php } ?>
<!-- LOGIN -->

<!-- USER -->
<?php if ($userdata) { ?>
<table width="100%" bgcolor="#FFFFFF" cellspacing="2" border="0" class="forumline">
<tr>
<td class="catrow" height="34">
<p align="center"><span class="catrowtext">User</span></td>
</tr>
<tr>
<td class="row1" align="left" width="100%">
<table border="0" width="88%" cellspacing="0" cellpadding="0" style="margin-left: 10; margin-right: 10; margin-top: 5; margin-bottom: 5">
<tr>
<td width="100%">
<p><?php if ($userdata['session_logged_in']) { ?>
<table>
<tr>
<td valign="top">
<?php if ($userdata['user_avatar_type'] > 0) { ?>
<?php if ($userdata['user_avatar_type'] == 1) { ?>
<img src="<?php echo $CFG['avatar_url']; ?>/<?php echo $userdata['user_avatar']; ?>" border="0" alt="" />
<?php } elseif ($userdata['user_avatar_type'] > 1) { ?>
<img src="<?php echo $CFG['avatar_gallery_url']; ?>/<?php echo str_replace(' ', '%20', $userdata['user_avatar']); ?>" border="0" alt="" />
<?php } ?>
<?php } else { ?>
&nbsp; <?php } ?>
</td>
<td valign="top">
<span class="gensmall">
Welcome back <?php echo $userdata['username']; ?>.
Your last visit was: <?php echo date($userdata['user_dateformat'], $userdata['user_lastvisit']); ?>.</span>
</td>
</tr>
</table>

<a href="<?php echo $phpbb_root_path; ?>privmsg.php?folder=inbox">You have
<?php if ($userdata['user_new_privmsg']) { echo $userdata['user_new_privmsg']; } else { echo 'no'; } ?> new<?php echo $userdata message<?php echo $userdata['user_new_privmsg'] == 1 ? '' : 's' ?></a><br />
<a href="<?php echo $phpbb_root_path; ?>search.php?search_id=newposts">Show new posts
(<?php echo $new_posts['total']; ?>)</a>
<br />
<a href="<?php echo $phpbb_root_path; ?>search.php?search_id=egosearch">Show your own posts</a><br />
<a href="<?php echo $phpbb_root_path; ?>search.php?search_id=unanswered">Show unreplied posts</a>
<?php } else { ?> Welcome, Guest <?php } ?>
</td>
</tr>
</table>


</td>
</tr>
</table>

<p />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php } ?>
<!-- USER -->[/code]
Copy linkTweet thisAlerts:
@beaaast337Jun 02.2006 — [code=php]<?php if ($userdata['user_new_privmsg']) { echo $userdata['user_new_privmsg']; } else { echo 'no'; } ?> new<?php echo $userdata message<?php echo $userdata['user_new_privmsg'] == 1 ? '' : 's' ?></a><br />[/code]

That is your line 85. See the problem??

no? Ok let me point it out. You haven't properly escaped PHP. Hard to see because of the way your code is written.

Easier to see it like this.
[code=php]
<?php
if ($userdata['user_new_privmsg']) {
echo $userdata['user_new_privmsg'];
} else {
echo 'no';
} ?> new<?php
echo $userdata message
<?php echo $userdata['user_new_privmsg'] == 1 ? '' : 's'
?>
</a><br />

[/code]


Now the fixed code...
[code=php]
<?php
if ($userdata['user_new_privmsg']) {
echo $userdata['user_new_privmsg'];
} else {
echo 'no';
} ?> new<?php
echo $userdata;
?> message<?php
echo $userdata['user_new_privmsg'] == 1 ? '' : 's';
?>
</a><br />

[/code]
Copy linkTweet thisAlerts:
@SheldonJun 02.2006 — BOB101, not to be mean, but what a mess of code.

Try looking for LCF's thread on Clean PHP structures.

I mean you closing you php and opening it right away, WHY?

[code=php]

<?php if ($userdata['user_avatar_type'] > 0) { ?>
<?php if ($userdata['user_avatar_type'] == 1) { ?>
<img src="<?php echo $CFG['avatar_url']; ?>/<?php echo $userdata['user_avatar']; ?>" border="0" alt="" />[/code]


Try this
[code=php]

<?php
if ($userdata['user_avatar_type'] > 0)
{
if ($userdata['user_avatar_type'] == 1)
{
echo("<img src="".$CFG['avatar_url']."/".$userdata['user_avatar']."" border="0" alt="" />");
}else{
}
}else{
}
?>
[/code]
×

Success!

Help @BOB101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...