...

View Full Version : why always error at the end?



likon
08-02-2007, 08:17 AM
<?php
if(!$USERNAME || !$PASSWORD) {
fieldsBlank();
die();
}

if(isset($NewUser)){
if(!($file=fopen("password.txt", "append"))){
print ("<title>Error</title></head><body> Could not open password file </body></html>");
die();
}
fputs($file,"$USERNAME,$PASSWORD\n");
userAdded($USERNAME);
}
else {
if(!($file=fopen("password.txt", "read"))){
print ("<title>Error</title></head>Could not open password file</body></html>");
die();
}

$userVerified=0;

while(!feof($file)&&!$userVerified){
$line=fgets($file,255);
$line=chop($line);
$field=split(",",$line,2);

//verify username...
if($USERNAME==$field[0]){
$userVerified=1;

if(checkPassword($PASSWORD,$field)==true){
accessGranted($USERNAME);
}else{
wrongPassword();
}
}

fclose($file);

if(!userVerified){
accessDenied();
}

function checkPassword($userpassword, $filedata){
if($userpassword==$filedata[1]){
return true; }
else {
return false;
}
}
function userAdded ($name)
{ print ("enjoy the site, $name");
}

function accessGranted ($name)
{
print ("Permission granted, $name");
}

function wrongPassword()
{
print ("You entered invalid password");
}

function fieldsBlank()
{
print ("Please fill in all blanks");
}
?>



I am wondering what part in script that always generates
"
Parse error: syntax error, unexpected $end in D:\xampp\htdocs\projects\password2.php on line 70"

while line 70 is the last line...
I know I am missing something, for sure
I dont quite understand this script though .particulary $name part...
I typed it from book, directly

Iszak
08-02-2007, 10:47 AM
Ok, you forgot to close your while loop on line 23, also you forgot to close your else on line 15



<?php
if(!$USERNAME || !$PASSWORD) {
fieldsBlank();
die();
}

if(isset($NewUser)){
if(!($file=fopen("password.txt", "append"))){
print ("<title>Error</title></head><body> Could not open password file </body></html>");
die();
}
fputs($file,"$USERNAME,$PASSWORD\n");
userAdded($USERNAME);
}
else { // --------------------- Line 15
if(!($file=fopen("password.txt", "read"))){
print ("<title>Error</title></head>Could not open password file</body></html>");
die();
}

$userVerified=0;

while(!feof($file)&&!$userVerified){ // --------------------- Line 23
$line=fgets($file,255);
$line=chop($line);
$field=split(",",$line,2);

//verify username...
if($USERNAME==$field[0]){
$userVerified=1;

if(checkPassword($PASSWORD,$field)==true){
accessGranted($USERNAME);
}else{
wrongPassword();
}
}

fclose($file);

if(!userVerified){
accessDenied();
}

function checkPassword($userpassword, $filedata){
if($userpassword==$filedata[1]){
return true; }
else {
return false;
}
}
function userAdded ($name)
{ print ("enjoy the site, $name");
}

function accessGranted ($name)
{
print ("Permission granted, $name");
}

function wrongPassword()
{
print ("You entered invalid password");
}

function fieldsBlank()
{
print ("Please fill in all blanks");
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum