Jump to content

parse error in php

- - - - -

  • Please log in to reply
2 replies to this topic

#1
ravi951

ravi951

    Newbie

  • Members
  • PipPip
  • 18 posts
hi all,
i have written a code using php for sessions.it will checks whether the
user is new or already registered...
i am getting the error as
Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\shopping1\task.php on line 16
kindly tell me what went wrong.
below is the code......

<?php

define("LIMIT", 10);

session_start();

//connect to database

$db = mysql_connect("localhost","root","") or die(mysql_error());

mysql_select_db("shopping", $db) or die(mysql_error());

$islogged = FALSE;

if(!isset($_SESSION["last_activity"]) || time() - $_SESSION["last_activity"] > LIMIT ) 

  {

    session_destroy();

    header("Location:logout.php");

  }

  $_SESSION["last_activity"] = time();

  $islogged = TRUE;


else 

{

if(isset($_POST["username"]) && isset($_POST["password"])) 

{

$result = mysql_query("SELECT * FROM login WHERE `username` = '$_POST["username"]' AND `password` = '$_POST["password"]'");

if(!$result) die( mysql_error());

  if(mysql_num_rows($result)) 

  {

   $_SESSION["last_activity"] = time();

   header("Location:products.php");

   $islogged = TRUE;

  }

  else 

  {

   $error = "username and password do not match";

  }

}

}

?>


<?php if(!$islogged): ?>

<form action="<?php $_SERVER['HTTP_REQUEST']?>" method="POST">

<?php if( isset($error) ): ?>

<p><?php echo $error;?></p>

<?php endif; ?>

Username:<input type="text" name="username" value="<?php isset($_POST['username']) ? $_POST['username'] : ''?>"

</br>

Password:<input type="password" name="password" value="<?php isset($_POST['password']) ? $_POST['password'] : ''?>"

</br>

<input type="submit" name="login" value="log in">

</form>

<?php endif; ?> 



#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
What you need to do is look at the characters directly before the "else" (as it mentions T_ELSE) on line 16

  $islogged = TRUE;  
else
{

Is "$islogged = TRUE; else {" correct code?

One observations also - You seem to be moving from braces, if(){} to older style syntax, if else endif; I would stick to one format even if one is more compact.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
ravi951

ravi951

    Newbie

  • Members
  • PipPip
  • 18 posts
yes the code is correct.but not getting the output.....




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users