Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I get this error with the code below. There is no line 53 though?

Error:

Parse error: syntax error, unexpected T_ELSE in /home/bitcoin/index.php on line 53

Code:

<?php
echo "<h1 align=\"center\">Welcome!</h1>";
echo "<h2 align=\"center\">This site is still being made! Check back soon!</h2>";

$code = $_POST['code'];

if(isset($_POST['submit'])) {

if($code == 'liam') {
echo "In!";
}else {
echo "Wrong! You entered \"$code\".";
}
}
?>

<html>
<head>
<title>Closed</title>
</head>
<body>
<p>If you are a tester, enter your code below!</p>
<form action="" method="post">
<?php
if($nopswd == 1) {
echo "<input type=\"text\" name=\"code\">";
else {
echo "<input type=\"password\" name=\"code\">";
}
?>
<br><input type="submit" name="submit" value="enter">
<input type="button" name="nopswd" value="Show Code" onClick="<?php showcode(); ?>">
</body>
</html>

<?php
function showcode()
{
$nopswd = 1;
header("Location: http://bitcoin.liamwli.co.uk/index.php");
}
?>
share|improve this question
Problem source: not bothering with indentation and/or lack of IDE. – mario Feb 19 '12 at 14:51
Well: 1. I can't. Editing directly from server with net2ftp installed on my server. 2. I don't have a server on my computer. – Liam W Feb 19 '12 at 14:55
Yes to Mario's point - also mixing HTML and business logic. Suggest you use a web framework or a templating library. – halfer Feb 19 '12 at 14:56
On any (serious) production system, one should never 'edit directly on the server' - it's asking for trouble. You should also have a LAMP stack on your development machine. – halfer Feb 19 '12 at 14:58
It's not really a 'serious' production system, but I will take that in mind. – Liam W Feb 19 '12 at 14:58

closed as too localized by NikiC, Ash Burlaczenko, mario, PeeHaa 埽, tereško Feb 19 '12 at 14:56

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

up vote 1 down vote accepted

It's typo, you're missing curly bracket before else

change this

<?php
if($nopswd == 1) {
    echo "<input type=\"text\" name=\"code\">";
else {
    echo "<input type=\"password\" name=\"code\">";
}
?>

to this

<?php
if($nopswd == 1) {
    echo "<input type=\"text\" name=\"code\">";
} else { // mising leading bracket here
    echo "<input type=\"password\" name=\"code\">";
}
?>
share|improve this answer

You are missing a bracket.

<?php
if($nopswd == 1) {
echo "<input type=\"text\" name=\"code\">";
else {
echo "<input type=\"password\" name=\"code\">";
}
?>

to

<?php
if($nopswd == 1) {
echo "<input type=\"text\" name=\"code\">";
} else {
echo "<input type=\"password\" name=\"code\">";
}
?>
share|improve this answer
Oh, thanks! I was also wondering why it said line 53 though? – Liam W Feb 19 '12 at 14:46
It says 53 because it doesn't know where the closing bracket should go, just that there is still a missing closing bracket at the point where it reaches parsing the entire file (ie the last line of the file)... so that's the line number it highlights as containing the problem – Mark Baker Feb 19 '12 at 14:49
Oh, that's understandable. Thanks. – Liam W Feb 19 '12 at 14:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.