0

ok my assignment is to make a login form that will accept a user name and password. if the user name and password don't match it doesnt do anything, but if it does it takes it to a website. my only problem is when i go to run it i get and error like this
Parse error: syntax error, unexpected $end in /home/bfinnegan/public_html/ta3.php on line 58...i dont know wat it means..need help please

<?php
$user="beatrice";
$pswrd="bean";
$redirect=false;
$max_attempts=false;

$num_attempts=(isset($_POST["num_attempts"])) ? $_POST["num_attempts"] + 1 : 0;
$username = (isset($_POST["username"])) ? $_POST["username"]: "";
if(!isset($_POST["username"]))
{       $msg="Welcome to the Cameron Page!";
}else if($_POST["username"]==$user && $_POST["password"]==$pswrd)//everything matches, move to webpage
{       $redirect=true;
        $msg="";
}else if($num_attempts>10)//kicks user out of program
{       $msg="Exceeded the limit of tries.";
        $max_attempts=true;
}else
{       $msg="Try again. Max number of attempts is 10";
}


$_POST["password"]="";
$guess=$_POST["guess"];

?>
<html>
<head>
<title>Welcome to Cameron</title>
</head>
<?php
if($redirection==true)
{
header("location:http://www.cameron.edu");
exit;
}
?>
</head>
<body>
<strong>
<?php echo $message ?>
</strong>
?>

<?php
if ($max_attempts==false)
{
echo "<form action= ".$_SERVER["PHP_SELF"];?> " method="POST"> ;
echo "User name :<br/><input type="text" name="username" value=".$username"><br/> ";
echo "Password : <br/><input type="password" name="password" value=''><br/> ";
echo "<input type="hidden" name="num_attempts" value=".$num_attempts"> ";
echo "</p> \n";
echo "<p><input type="submit" value="submit your guess"></p>";
}
?>
</form>
</body>
</html>
4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Gori
0

From what I can tell, it looks as though you have a random php end tag "?>" there on line 42 that doesn't belong. If you clear that out, it might solve that error you're receiving.

0

IT looks to me like you didn't escape the double quotes, remember that when you have a double quote inside an echo you use \" instead of ". Also, in your code there are a few places where you used an ending ?> tag without the <?php at the beginning. Hope it helps

0

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/bfinnegan/public_html/ta3.php on line 48

ok i did what you guys advised and i got this error now. i post from
44 to 54

<?php
if ($max_attempts==false)
{
echo "<form action= '".$_SERVER["PHP_SELF"]."' method=\"POST\"> ;
echo "User name :<br/><input type='text' name='username' value='"\.$username\"'><br/> ";
echo "Password : <br/><input type='password' name='password' value=''><br/> ";
echo "<input type='hidden' name='num_attempts' value='.$num_attempts'> ";
echo "</p> \n";
echo "<p><input type=\"submit\" value=\"submit your guess\"></p>";
}
?>
0

Alright, I just took what you originally had there for those lines and added the escapes like adyopo mentioned. You just missed a few with your second posting. For example, on line 4 (of your second post) you need quotation marks at the very end before the semi-colon. On lines 5 and 7 it appears you try to concatenate the values with the string, however you put the period, '.' only before the value. Take a look at the following, I think it should work...

<?php
	if ($max_attempts==false)
	{
		echo "<form action= " . $_SERVER["PHP_SELF"] . " method=\"POST\">";
		echo "User name :<br/><input type=\"text\" name=\"username\" value=\"" . $username . "\"><br /> ";
		echo "Password : <br/><input type=\"password\" name=\"password\" value=''><br />";
		echo "<input type=\"hidden\" name=\"num_attempts\" value=\"" . $num_attempts . "\">";
		echo "</p> \n";
		echo "<p><input type=\"submit\" value=\"submit your guess\"></p>";
	}
?>
0

ok well i did make the changes and here are the errors i got.
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/bfinnegan/public_html/ta3.php on line 48

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/bfinnegan/public_html/ta3.php on line 48

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/bfinnegan/public_html/ta3.php on line 50

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/bfinnegan/public_html/ta3.php on line 50

this is confusing

0

ok never mind. i got it to work! thank you so much for the help!

0

try this code

<?php
$user="beatrice";
$pswrd="bean";
$redirect=false;
$max_attempts=false;
$num_attempts=(isset($_POST["num_attempts"])) ? $_POST["num_attempts"] + 1 : 0;
$username = (isset($_POST["username"])) ? $_POST["username"]: "";
if(!isset($_POST["username"]))
{ $msg="Welcome to the Cameron Page!";
}else if($_POST["username"]==$user && $_POST["password"]==$pswrd)//everything matches, move to webpage
{ $redirect=true;
$msg="";
}else if($num_attempts>10)//kicks user out of program
{ $msg="Exceeded the limit of tries.";
$max_attempts=true;
}else
{ $msg="Try again. Max number of attempts is 10 & it's your ".$num_attempts." attempt" ;
}
$_POST["password"]="";
//$guess=$_POST["guess"];
?>
<html>
<head>
<title>Welcome to Cameron</title>
</head>
<?php
if($redirect == true)
{
header("location:http://www.cameron.edu");
exit;
}
?>
</head>
<body>
<strong>
<?php echo $msg; ?>
</strong>
<?php
if ($max_attempts==false)
{
echo "<form action= ".$_SERVER["PHP_SELF"]." method=\"POST\">";
echo "User name :<br/><input type=\"text\" name=\"username\" value=\"".$username."\"><br/>";
echo "Password : <br/><input type=\"password\" name=\"password\" value=\"\"><br/>";
echo "<input type=\"hidden\" name=\"num_attempts\" value=\"".$num_attempts."\">";
echo "</p> \n";
echo "<p><input type=\"submit\" value=\"submit your guess\"></p>";
}
  ?>
</form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.