Page 1 of 1

Parse error: syntax error, unexpected T_ELSE

Posted: Fri Apr 08, 2011 10:51 pm
by liyun88
hi,i face some problem.. when the user clicks the submit button and link to saveComment.php,i nid to check if the user is member,then can insert their comment in to database..but if the user not is member,then will pop out the messages..what wrong with my code??i gt the error that is Parse error: syntax error, unexpected T_ELSE..
can anyone help me to check and correct the code??thanks in advance..

Code: Select all

<?php

require_once 'config.php' ;
require_once 'application.php' ;

 $id = $_SESSION['id'];
$username = $_SESSION["username"];
$comment = $_POST["comment"];
if ($id = $_SESSION['id'])
{
$query = 'INSERT INTO comment set id =  "' . mysql_real_escape_string($id) . '",
username =  "' . mysql_real_escape_string($username) . '", 
comment =  "' . mysql_real_escape_string($comment) . '",date = "' . date('Y-m-d H:i:s') . '"'; 
$result = mysql_query($query);  
else{ 
  echo"<script>alert(\"Please register as member to comment\")</script>";
  }
  }
redirect("comment2.php");
?>

Re: Parse error: syntax error, unexpected T_ELSE

Posted: Fri Apr 08, 2011 11:01 pm
by fugix
you didnt end your if function with a } before starting your else statement

Re: Parse error: syntax error, unexpected T_ELSE

Posted: Sat Apr 09, 2011 12:41 am
by liyun88
fugix wrote:you didnt end your if function with a } before starting your else statement
thanks ya...it works fine now.. :D

Re: Parse error: syntax error, unexpected T_ELSE

Posted: Sat Apr 09, 2011 12:41 am
by fugix
no problem...;)