Parse error: syntax error, unexpected T_ELSE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

Parse error: syntax error, unexpected T_ELSE

Post by liyun88 »

hi,i face some problem about T_ELSE..i dont know how to put them..
actually i want that if the product is already in the shopping cart,it will not insert into cart table,but if the product is not in the shopping cart,it will insert into shopping cart..so i use if else function..i have error in the code..
can anyone help me to solve them??thanks in advance..

Code: Select all

<?php 
session_start();
require_once 'config.php' ;
require_once 'application.php' ;

//var_dump($_FILES);
  
 $id = $_SESSION['id'];
 $username = $_SESSION['username'];
 $pid=$_POST['pid'];
 $pname=$_POST['pname'];
 $uprice=$_POST['uprice'];
 $quantity=$_POST['quantity'];
 
  $query = "SELECT * FROM products WHERE pid = $pid"; 
  $result = mysql_query($query);
  $row=mysql_fetch_row($result);
  $pid =   $row[1];
  $pname = $row[3];
  $price = $row[5];
  $promo = $row[6];
  
  if ($promo != '0.00')
			{ $uprice = $promo; }
			else
			{ $uprice = $price; }
		

 
  $query1 = "SELECT * FROM register WHERE id =$id";   
  $result1 = mysql_query($query1);
  $row1=mysql_fetch_row($result1);
  
  if(isset($_SESSION['pid'])){
     if(in_array($_POST['pid'],$_SESSION['pid'])){
	   header('Content-type:text/html;charset=utf-8');
	   echo"<script>alert(\"Your product is in your shopping cart!\")</script><script>window.location='home.php?id=$id'</script>";  
	   
	   }
     }
	  
	   $_SESSION['pid'][] = $_POST['pid'];
	   $_SESSION['pname'][] = $_POST['pname'];
	   $_SESSION['uprice'][] = $_POST['uprice'];
	   $_SESSION['quantity'][]=$_POST['quantity'];
  
        else {
		$result2 = mysql_query("INSERT INTO cart  VALUES('','$id','$username','$pid','$pname','$uprice','$quantity')");

				 
 echo"<script>alert(\"Saved Successfully!\")</script><script>window.location='home.php?id=$id'</script>";  }
  
?>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Parse error: syntax error, unexpected T_ELSE

Post by fugix »

its because you set session variables after the last if..the else must come the line after the closing if function bracket
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

Re: Parse error: syntax error, unexpected T_ELSE

Post by liyun88 »

but if i close } after set session,it not have function not display blank screen..
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Parse error: syntax error, unexpected T_ELSE

Post by fugix »

Code: Select all

}
         
           $_SESSION['pid'][] = $_POST['pid'];
           $_SESSION['pname'][] = $_POST['pname'];
           $_SESSION['uprice'][] = $_POST['uprice'];
           $_SESSION['quantity'][]=$_POST['quantity'];
 
        else {


should be....


}
else {
         
           $_SESSION['pid'][] = $_POST['pid'];
           $_SESSION['pname'][] = $_POST['pname'];
           $_SESSION['uprice'][] = $_POST['uprice'];
           $_SESSION['quantity'][]=$_POST['quantity'];
  
Post Reply