/    Sign up×
Community /Pin to ProfileBookmark

parse error but i cant understand

hi all, i am getting this dump

[code=html]Parse error: parse error in /Users/sheldon/Sites/ebs/forgot.php on line 36[/code]

and here is the code

[code=php]<?php
session_start(); // Maintain session state
header(“Cache-control: private”); // Fixes IE6’s back button problem.

// Are we logged in, or logging in?
if(@$_SESSION[‘user’]) header(“location: login.php”);
else{
?>

<?php include (‘library/top.php’); ?>
<?php $page=”ForgotPass”; ?>

<?php

$Nemail = $_POST[’email’];

// Include the flat-file
$file = file(“users.php”) or die(“Problem getting the user details flat-file [users.php]”);

// Get the size of file
$totalLines = sizeof($file);

// Get the users details line by line
$line = 0;
$match = 0;
do{
// Check the line isn’t a comment
if(“//” != substr($file[$line], 0, 2)){
// Break our records up
@list($username, $password, $permission, $email, $url, $dob, $location, $joined) = explode(“<del>”, $file[$line]);

// Check the username and passwords match
if(($Nemail) == ($email) $match = 1;
else $match = 0;
}

// Exit loop if match found
if($match) break;

// Increment line count
$line++;
} while($line < $totalLines);

// Include the file or send them back
if($match){
$_SESSION[“user”] = $user;
$_SESSION[“pass”] = $pass;
$_SESSION[“permission”] = $permission;
$_SESSION[“email”] = $email;
$_SESSION[“url”] = $url;
$_SESSION[“dob”] = $dob;
$_SESSION[“location”] = $location;
$_SESSION[“joined”] = $joined;

// Refresh page
header(“location: “. $_SERVER[‘PHP_SELF’]);

?>

<p>
<?php print $_SESSION[’email’]; ?>
</p>
<p>
<?php print $_SESSION[‘pass’]; ?>
</p>

<?php include (‘library/bottom.php’); ?>
[/code]

the error is on the line

[code=php]
if(($Nemail) == ($email) $match = 1;
[/code]

I am trying to match the address (Nemail) from the form with the addresses in the database and pull both the email address and the users password.

Any ideas?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 05.2005 — Parentheses are not balanced. Try:
[code=php]
if($Nemail == $email) $match = 1;
else $match = 0;
[/code]

If you like terse code, you can combine it into a one-liner using the ternary operators:
[code=php]
$match = ($Nemail == $email) ? 1 : 0;
[/code]
Copy linkTweet thisAlerts:
@SheldonauthorJun 05.2005 — Thanks NogDog, i have put that in and now get [code=html]Parse error: parse error in /Users/sheldon/Sites/ebs/forgot.php on line 36[/code] but to my counting that line 74 is one line after my last line?


Sheldon
Copy linkTweet thisAlerts:
@NogDogJun 05.2005 — Missing a couple closing curly-braces. Make the last part...
[code=php]
<?php
}
}
include ('library/bottom.php'); ?>
[/code]

...and it will parse, but check to make sure that is the correct logic for where you want their related blocks to close.
Copy linkTweet thisAlerts:
@SheldonauthorJun 05.2005 — Thanks NogDog, it works but gives this dump now

[code=html]Warning: Cannot modify header information - headers already sent by (output started at /Users/sheldon/Sites/ebs/forgot.php:11) in /Users/sheldon/Sites/ebs/forgot.php on line 58
[email protected] <!--email address entered on the page before-->[/code]


So it carries my email from the form on the page before but from what i an see cant access my file or magane the header files


Thanks

Sheldon
Copy linkTweet thisAlerts:
@SheldonauthorJun 05.2005 — Hi i moved a [b]}[/b] and it workes better, but still wont access the userfile? and you need to refresh the page to remove the error message?


This is the code now


[code=php]<?php

session_start(); // Maintain session state
header("Cache-control: private"); // Fixes IE6's back button problem.

// Are we logged in, or logging in?
if(@$_SESSION['user']) header("location: login.php");
else{
?>


<?php include ('library/top.php'); ?>
<?php $page="ForgotPass"; ?>



<?php

$Nemail = $_POST['Nemail'];

// Include the flat-file
$file = file("users.php") or die("Problem getting the user details flat-file [users.php]");

// Get the size of file
$totalLines = sizeof($file);

// Get the users details line by line
$line = 0;
$match = 0;
do{
// Check the line isn't a comment
if("//" != substr($file[$line], 0, 2)){
// Break our records up
@list($username, $password, $permission, $email, $url, $dob, $location, $joined) = explode("<del>", $file[$line]);

// Check the username and passwords match
$match = ($Nemail == $email) ? 1 : 0;
}

// Exit loop if match found
if($match) break;

// Increment line count
$line++;
} while($line < $totalLines);

// Include the file or send them back
if($match){
$_SESSION["user"] = $user;
$_SESSION["pass"] = $pass;
$_SESSION["permission"] = $permission;
$_SESSION["email"] = $email;
$_SESSION["url"] = $url;
$_SESSION["dob"] = $dob;
$_SESSION["location"] = $location;
$_SESSION["joined"] = $joined;

// Refresh page
header("location: ". $_SERVER['PHP_SELF']);

}
?>

<p>
<?php print $_SESSION['email']; ?>
</p>
<p>
<?php print $_SESSION['pass']; ?>
</p>







<?php

}

include ('library/bottom.php'); ?>[/code]




Thanks Sheldon
Copy linkTweet thisAlerts:
@NogDogJun 05.2005 — You cannot have anything that's outputting text to the browser prior to executing any header() functions. Doing something like this...
[code=php]
<?php
# bunch of php code
?>


<?php
# more php code
header("stuff to output to HTTP header");
?>
[/code]

...is actually outputing newlines between the two blocks of PHP code.

You need to start the page with <?php with no spaces of any kind before it, and not do any kind of echo, print, etc. (including from within include files) until you have done any and all header() calls.
Copy linkTweet thisAlerts:
@SheldonauthorJun 05.2005 — ok, i have removed the line [code=html] // Refresh page
header("location: ". $_SERVER['PHP_SELF']); [/code]


and the page loads with no errors,


but it only displayed the email address called from the form, not the password aswell? or anything from the flatfile database either?

Any ideas on why it is not calling the file?



Thanks

Sheldon
×

Success!

Help @Sheldon 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.18,
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,
)...