Help on website! Syntax error. Web 

Newbie Spellweaver
Joined
May 22, 2012
Messages
28
Reaction score
0
Error i gotten :

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\site\assets\header.php on line 35

What's in the file :

<? } else {
if (isset($_POST['login'])) {
$u = mysql_real_escape_string(stripslashes($_POST['username']));
$p = mysql_real_escape_string(stripslashes($_POST['password']));
$s = mysql_query("SELECT * FROM `accounts` WHERE `name`='" . $u . "'") or die(mysql_error());
$i = mysql_fetch_array($s);

if ($i['password'] == hash('sha512', $p . $i['salt']) || sha1($p) == $i['password']) {
$users = mysql_query("SELECT * FROM `accounts` WHERE `name`='" . $i['name'] . "' AND `password`='" . $i['password'] . "'") or die(mysql_error());
$auser = mysql_fetch_array($users);
$_SESSION['id'] = $auser['id'];
$_SESSION['name'] = $auser['name'];
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0.2; URL=?page=index\">";
} else {
echo "<div class='invalid'><p>Invalid username or password.</p></div>";
}
}
include("assets/nav.php");
}

The last line is line 35.
Help is pretty much appreciated.
 
php code starts with <?php and ends with ?>
so your php code should start with : <?php
and end with: ?>

at the first line, change "<?" to "<?php"
and after the 35th line add "?>"

without the quotes of course
 
Upvote 0
php code starts with <?php and ends with ?>
so your php code should start with : <?php
and end with: ?>

at the first line, change "<?" to "<?php"
and after the 35th line add "?>"

without the quotes of course

Both of those statements are false. Perhaps you should read up on the documentation
 
Upvote 0
Both of those statements are false. Perhaps you should read up on the documentation

first <?php and ?> are the standard php tags.
secondly if he wants to use the short open tags he needs to enable it which means its disabled (unless he enabled it, and of couse I can't know)
we omit the php closing tag in case that yours file contains ONLYPHP code and no escaped HTML code.
its recommended to omit the php closing tag when you use include or require so at the end of the file won't be any whitespaces (which generated by include files), but if the php file has html code you should use the php closing tag.
and in this case, he gave us only a part of the file so I can't guess what does he has in his file.
 
Upvote 0
first <?php and ?> are the standard php tags.
secondly if he wants to use the short open tags he needs to enable it which means its disabled (unless he enabled it, and of couse I can't know)
we omit the php closing tag in case that yours file contains ONLYPHP code and no escaped HTML code.
its recommended to omit the php closing tag when you use include or require so at the end of the file won't be any whitespaces (which generated by include files), but if the php file has html code you should use the php closing tag.
and in this case, he gave us only a part of the file so I can't guess what does he has in his file.

I never said what tag is the standard. The link I provided was meant to inform you of the fact that <?php and ?> are not the only way to declare a PHP file. In fact, greater support for the the short tag (<?= ?>) was added in PHP 5.4, so this should speak for itself as to what is acceptable or not. Most updated web servers ship with 5.4 or higher.

I'm not sure where you're getting information about omitting the end tag if there's no html code, please provide a source.
--
The issue here is most likely the following code block, or an encoding issue.
PHP:
<? }
 
Upvote 0
Ok, let me clear some things:

1) the user who post his thread came for help, from what i saw it, he gets syntax error because he is missing the php end tag.
by reading his script I can't guess if he enabled short tag option if he didn't so he can't use it which means his code won't run.
so i "told" him to use the standard tag, its the, how to call it, the "smart" way of solving this problem because I can't know if he enabled the short tag option or not, so i went on "smart" and not on a "guess". In fact, the issue isn't causing by the line "<? }" if you would read the error and see that the error caused by line 35 and if you read his post he writes that the last line is line 35, since he doesn't have the ending tag i assumed he had to add it.

2) I never said "must" I said "should" different meanings, from the reasons above, I chose to tell him how to use the standard php tags.
It also means this isn't the only way, did I say its the only way? from what have you conclude I don't know about other syntaxes of PHP tags?
It seems like you're very proud.

3) About omitting the php closing tag, that's really ironic, you may read up on the documentation.
you know what i'll explain and give you some examples why its better to omit the PHP closing tag when you can.
well, when you using the PHP closing tag and then you have some whitespaces the whitespaces will be printed.
for example:
PHP:
<?php
       echo "hello";
?>*       *
(I marked the whitespaces with " * ")
the output will be:
Code:
hello*       *
but if we omit the PHP closing tag the output will be only "hello" without whitespaces even if we have whitespaces, the output will be:
Code:
hello
So, in case we don't have HTML code we will prefer to omit the closing tag, but if we have so of course we can't omit the closing tag or we'll get an error.
You may read this Note .

4) Um about the short tag (<?= ?>), well first, its not a short tag, its a short syntax for echo() while its using the PHP short open tags with an equals sign after the opening tag.
And yeah in PHP 5.4 was added a support for this syntax, using the syntax without enabling short_open_tags option, but in lower versions of PHP you can't use this syntax without enabling the short open tags option, you have to enable it first.
You may want to read about it .

I think I made myself clear.
 
Last edited:
Upvote 0
Ok, let me clear some things:

1) the user who post his thread came for help, from what i saw it, he gets syntax error because he is missing the php end tag.
by reading his script I can't guess if he enabled short tag option if he didn't so he can't use it which means his code won't run.
so i "told" him to use the standard tag, its the, how to call it, the "smart" way of solving this problem because I can't know if he enabled the short tag option or not, so i went on "smart" and not on a "guess". In fact, the issue isn't causing by the line "<? }" if you would read the error and see that the error caused by line 35 and if you read his post he writes that the last line is line 35, since he doesn't have the ending tag i assumed he had to add it.

2) I never said "must" I said "should" different meanings, from the reasons above, I chose to tell him how to use the standard php tags.
It also means this isn't the only way, did I say its the only way? from what have you conclude I don't know about other syntaxes of PHP tags?
It seems like you're very proud.

3) About omitting the php closing tag, that's really ironic, you may read up on the documentation.
you know what i'll explain and give you some examples why its better to omit the PHP closing tag when you can.
well, when you using the PHP closing tag and then you have some whitespaces the whitespaces will be printed.
for example:
PHP:
<?php
       echo "hello";
?>*       *
(I marked the whitespaces with " * ")
the output will be:
Code:
hello*       *
but if we omit the PHP closing tag the output will be only "hello" without whitespaces even if we have whitespaces, the output will be:
Code:
hello
So, in case we don't have HTML code we will prefer to omit the closing tag, but if we have so of course we can't omit the closing tag or we'll get an error.
You may read this Note .

4) Um about the short tag (<?= ?>), well first, its not a short tag, its a short syntax for echo() while its using the PHP short open tags with an equals sign after the opening tag.
And yeah in PHP 5.4 was added a support for this syntax, using the syntax without enabling short_open_tags option, but in lower versions of PHP you can't use this syntax without enabling the short open tags option, you have to enable it first.
You may want to read about it .

I think I made myself clear.

I guess you misinterpreted the tone of my post, I haven't done much research on this subject, because I tend to not to use short tags or place HTML in my PHP documents at all. All I was asking for were some sources so that I could read more about it, so thanks for providing that!
 
Last edited:
Upvote 0
I guess you misinterpreted the tone of my post, I haven't done much research on this subject, because I tend to not to use short tags or place HTML in my PHP documents at all. All I was asking for were some sources so that I could read more about it, so thanks for providing that!

Oh well, It seems like I didn't understand your intention in your posts. Well it seemed to me like you think I don't know nothing in PHP or something like that. I'm glad you make it clearly, I don't afraid to be wrong and if I do I will be happy if someone will correct me, so I won't do this mistake again, the most important thing with having a mistake is come and ask why I'm mistaken, trust me, I don't care if I make mistakes I just hope there is someone who will correct me :)

Thanks,
Have a nice weekend!
 
Upvote 0
Back