Login | Register | FAQ
Anonymous

Syntax error

+ Post a reply

Page 1 of 1


Syntax error

by JereWoo » Tue May 01, 2012 5:56 pm

Code: Select all
<html>
   <head>
      <title>Login</title>
   </head>

   <body>
   <form method="post" action="login.php">

   <p>Username: <input type="text" name="username"/></p>
   <p>Password: <input type="text" name="password"/></p>

   <p><input type="submit" value="let me in" /></p>
   </form>
   </body>
</html>


Code: Select all
<html>
   <head>
      <title>Login</title>
   </head>

   <body>

   <?php
   
   if ($_POST["username"] == "php" && $_POST["password"] == "php")
   {
      session_start();
      $_SESSION["Login"] = "YES";
      echo "<h1> you are now logged in"
      echo "<p><a href='document.php'>Link to protected file</a><p/>";
   }
   else
   {
      session_start();
      $_SESSION["login"] = "no";
      echo "<h1> incorrect login </h1>";
      echo "<p><a href='document.php'>Link to protected file</a><p/>";
   }
?>
   </body>
</html>


Code: Select all
<?php
   session_start();

   if ($_SESSION["Login"] !="YES")
   {
      header("Location: form.php")
   }

?>

<html>
   <head>
      <title>protected files</title>
   </head>

   <body>
      <h1>This document is protected</h1>
      <p>login if you want to see ;)</p>
   </body>
</html>


"Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\xampp\htdocs\login.php on line 15"
It says that when I try to log in, I do not see the error could someone please point it out :D
User avatar

JereWoo

  • Posts: 4
  • Joined: Tue May 01, 2012 5:50 pm

Re: Syntax error

by chrisf1288 » Tue May 01, 2012 8:35 pm

<html>
<head>
<title>Login</title>
</head>

<body>

<?php

if ($_POST["username"] == "php" && $_POST["password"] == "php")
{
session_start();
$_SESSION["Login"] = "YES";
echo "<h1> you are now logged in</h1>"; // Your forgot this semicolon and the ending h1 tag
echo "<p><a href='document.php'>Link to protected file</a><p/>";
}
else
{
session_start();
$_SESSION["login"] = "no";
echo "<h1> incorrect login </h1>";
echo "<p><a href='document.php'>Link to protected file</a><p/>";
}
?>
</body>
</html>
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am

Re: Syntax error

by JereWoo » Wed May 02, 2012 4:06 pm

thank you that fixed it guess I was staring at it to long lol
now I have a new problem which makes no sense




Code: Select all
<?php
   session_start();

   if ($_SESSION["Login"] !="YES")
   {
      header("Location: form.php")
   }

?>

<html>
   <head>
      <title>protected files</title>
   </head>

   <body>
      <h1>This document is protected</h1>
      <p>login if you want to see ;)</p>
   </body>
</html>


Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\document.php on line 6 i don't see how its error its supposed to be there however i tried removing it anyway and it gave me this....
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\document.php on line 20 there isn't a $end do I need to add one?
User avatar

JereWoo

  • Posts: 4
  • Joined: Tue May 01, 2012 5:50 pm

Re: Syntax error

by chrisf1288 » Wed May 02, 2012 4:40 pm

<?php
session_start();

if ($_SESSION["Login"] !="YES")
{
header("Location: form.php");
}

?>

<html>
<head>
<title>protected files</title>
</head>

<body>
<h1>This document is protected</h1>
<p>login if you want to see ;)</p>
</body>
</html>



Well the problem is you forgot the semicolon again. But don't worry, that happens to everyone from time to time.
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am

Re: Syntax error

by JereWoo » Wed May 02, 2012 5:09 pm

damn semicolons -_-
I'm getting this error now:Parse error: syntax error, unexpected $end in C:\xampp\htdocs\document.php on line 20
I haven't had any problems up to this lesson lol
User avatar

JereWoo

  • Posts: 4
  • Joined: Tue May 01, 2012 5:50 pm

Re: Syntax error

by chrisf1288 » Wed May 02, 2012 5:13 pm

You kept the curly bracket in right?
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am

Re: Syntax error

by JereWoo » Wed May 02, 2012 5:20 pm

yeah I forgot to put it back lol Thank you for all your help :D
User avatar

JereWoo

  • Posts: 4
  • Joined: Tue May 01, 2012 5:50 pm

Re: Syntax error

by chrisf1288 » Wed May 02, 2012 5:37 pm

Welcome
User avatar

chrisf1288

  • Posts: 128
  • Joined: Sun Jun 26, 2011 1:01 am


+ Post a reply

Page 1 of 1