Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 21st, 2011, 01:18 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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; ?>
Reply With Quote
  #2 (permalink)  
Old September 21st, 2011, 09:25 AM
Authorized User
Points: 319, Level: 6
Points: 319, Level: 6 Points: 319, Level: 6 Points: 319, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2010
Location: MIssouri
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 
{
Reply With Quote
  #3 (permalink)  
Old September 21st, 2011, 09:29 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.......
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:50 PM.


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