1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

parse error in php

Discussion in 'PHP' started by ravi951, Sep 21, 2011.

  1. ravi951

    ravi951 New Member

    Joined:
    Aug 9, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    web developer
    Location:
    hyderabad
    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; ?> 
    
     
  2. pein87

    pein87 New Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    0
    Occupation:
    Web Dev
    Location:
    Limbo
    above the else statement you have code. You can't have that there and the else statement must directly follow the if before it, i.e this:

    PHP:
    if()
    {

    }
    else
    {

    }
    and not

    PHP:
    if()
    {

    }
    $boo;
    $booboo;
    else
    {

    }
    try this, I moved the variables into the else statement and fixed your br tags.

    PHP:
    <?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");
    }
    else 
    {
    $_SESSION["last_activity"] = time();
      
    $islogged TRUE;
      
    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; ?>
     
  3. raixyz

    raixyz Banned

    Joined:
    Oct 18, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    "i am using wampserver with php version 5.3.0 i am getting this error in my php.

    Parse error: parse error in C:\wamp\www\contactform.php on line 16


    and i cant figure out what is wrong with my scripting.


    the code is...

    <?php

    $to = "hiddenmirageads@gmail.com";
    $subject = "New Special Effects";

    $body = "New Form Request!
    Nickname: ".$_POST['username']."
    Email: ".$_POST['Email']."
    Description of effect: ".$_POST['Describe']."
    Provide Footage: ".$_POST['footage']."
    Length of video to edit: ".$_POST['Timeofvideo']."
    Price range: ".$_POST['checkbox']."
    Time range: ".$_POST['Time']."
    Paypal: ".$_POST['Paypal'].""

    mail($to,$subject,$body)

    ?>

    line 16 is the mail line. someone please tell me what is going wrong."
     
  4. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    The syntax u are using for mail() seems to be incorrect..
    The correct one is mail("$to", "$subject",
    $message, "From:" . $email);
    >u are missing the semicolon<
     

Share This Page