Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2011, 01:18 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default parse error in php

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......
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; ?>
 
Old September 21st, 2011, 09:25 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default parse Eror

The code
Code:
   $_SESSION["last_activity"] = time();
  $islogged = TRUE;
Should be moved. Looks Like you could close the if statement after the above code... ie..

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 
{
 
Old September 21st, 2011, 09:29 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default reply

first i need to check whether session exists or not.
if not exists then using the time function i need to store that using session id
else if exists then no need of creating time function
how yto modify in the above code so that it will work like above said.......





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Parse Error -- HELP cc9of13 PHP How-To 0 June 21st, 2010 07:11 PM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
php parse error ajit_kunte BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 May 2nd, 2005 07:24 AM
MySQL & PHP Parse error Stuart BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 March 17th, 2005 03:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.