Jump to content

Parse error: parse error in process_avatar line 84??


deansaddigh

Recommended Posts

Hi, i have some code and i cant for the life of me figure out why im getting a parse error on the last "else" statement, can you not have 2 else statements after each other?

 

<?php
session_start();
if (isset($_SESSION['email']) == false) 
{
	header("Location:../index.php");
	exit();
}

include ("../db/connection.php");

//Create the folder if it does not already exist
if(!file_exists('avatars'))
    {
        if(mkdir('avatars'))
        {
            echo 'Folder Avatar created';
        }
        else
        {
              echo 'Error creating folder ' . 'avatars';
        }
    }


    // Where the file is going to be placed 
    $target_path = "avatars/";

//This path will be stored in the database as it does not contain the filename
$path = $target_path;
    
    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

$target_path = "avatars/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
{
	echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
	$filename =  $_FILES['uploadedfile']['name'];


	$email =$_SESSION['email'];

	//build sql statement to compare data entered to data in db
	$query = "SELECT User_id FROM user WHERE Email = '$email'"; 	
	$result = mysql_query($query,$conn)	
		or die ("Unable to perform query");

	//Retrieve the data that is stored in the $query array
	$row= mysql_fetch_array($result);
	$userid = $row['User_id'];

		//See wether user allready has avatar in table

         		if ($userid !==NULL)
              		{
               			$query= "UPDATE avatar SET Avatar_path = '$filename', Avatar_name = '$path'
               			Where User_id=" .$userid;
               			$result =mysql_query($query, $conn)
               			or die ("unable to perform query");
               		}

			else 
				{

					//Store the filename, path other criteria in the database 
					$query = "INSERT INTO avatar(Avatar_name, Avatar_path, User_id)
					VALUES('$filename', '$path', $userid)";

					//Perform the query
					$addphoto = mysql_query($query, $conn)
						or die("Unable to add the photo details to the database");

					$message = 'Upload Successful';

					//Close the connection to the database	
					mysql_close($conn);
					header("Location: avatar_upload.php? message=$message");

				} 
else
{	
	//Error uploading tell admin
	$message = 'There was an error uploading the file, please try again!';

	//Close the connection to the database	
	mysql_close($conn);
	header("Location: avatar_upload.php? message=$message");

}
?>

Link to comment
Share on other sites

I can't see a closing brace for this if statement

 

  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))

 

 

<?php
   session_start();
   if (isset($_SESSION['email']) == false) 
   {
      header("Location:../index.php");
      exit();
   }
   
   include ("../db/connection.php");
   
   //Create the folder if it does not already exist
   if(!file_exists('avatars'))
    {
        if(mkdir('avatars'))
        {
            echo 'Folder Avatar created';
        }
        else
        {
              echo 'Error creating folder ' . 'avatars';
        }
    }
   
   
    // Where the file is going to be placed 
    $target_path = "avatars/";
   
   //This path will be stored in the database as it does not contain the filename
   $path = $target_path;
       
    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
   
   $target_path = "avatars/";

   $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
   
   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
   {
      echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
      $filename =  $_FILES['uploadedfile']['name'];
      
      
      $email =$_SESSION['email'];
      
      //build sql statement to compare data entered to data in db
      $query = "SELECT User_id FROM user WHERE Email = '$email'";    
      $result = mysql_query($query,$conn)   
         or die ("Unable to perform query");
         
      //Retrieve the data that is stored in the $query array
      $row= mysql_fetch_array($result);
      $userid = $row['User_id'];
      
         //See wether user allready has avatar in table
            
               if ($userid !==NULL)
                    {
                        $query= "UPDATE avatar SET Avatar_path = '$filename', Avatar_name = '$path'
                        Where User_id=" .$userid;
                        $result =mysql_query($query, $conn)
                        or die ("unable to perform query");
                     }
               
            else 
               {
      
                  //Store the filename, path other criteria in the database 
                  $query = "INSERT INTO avatar(Avatar_name, Avatar_path, User_id) 
                  VALUES('$filename', '$path', $userid)";
                  
                  //Perform the query
                  $addphoto = mysql_query($query, $conn)
                     or die("Unable to add the photo details to the database");
                  
                  $message = 'Upload Successful';
                     
                  //Close the connection to the database   
                  mysql_close($conn);
                  header("Location: avatar_upload.php? message=$message");
                  
               }
}
   else
   {   
      //Error uploading tell admin
      $message = 'There was an error uploading the file, please try again!';
      
      //Close the connection to the database   
      mysql_close($conn);
      header("Location: avatar_upload.php? message=$message");
      
   }
?>

Link to comment
Share on other sites

on the code he posted he had

 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  
{
  
            
         if ($userid !==NULL)
           {
            
           }
       else 
           {
      
                  
                  
           } 
   else
   {   
    
   }

 

 

So yes there is a missing braket, which is why he has a parse error on line 84.

Link to comment
Share on other sites

What is the parse error? did you put the missing bracket in?

Ok i have changed it to this now

elseif($userid ==NULL) 
				{

					//Store the filename, path other criteria in the database 
					$query = "INSERT INTO avatar(Avatar_name, Avatar_path, User_id)
					VALUES('$filename', '$path', $userid)";

					//Perform the query
					$addphoto = mysql_query($query, $conn)
						or die("Unable to add the photo details to the database");

					$message = 'Upload Successful';

					//Close the connection to the database	
					mysql_close($conn);
					header("Location: avatar_upload.php? message=$message");

				} 

 

now im getting a parse error on the next section straight after which is this

else
{	
	//Error uploading tell admin
	$message = 'There was an error uploading the file, please try again!';

	//Close the connection to the database	
	mysql_close($conn);
	header("Location: avatar_upload.php? message=$message");

}
?>

Link to comment
Share on other sites

You Should Do

if (command("defined")) {

} else {


} elseif (command("defined")) {


}

 

It's not if .. else .. else if. You'd never reach the last else if cause else would always be run. It's if.. else if.. else.. With as many else if conditions as you like.

Link to comment
Share on other sites

Also by looking at the code that last else statement is if this fails.

 

"move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)"

 

Its not linked to the the userid checsk. so I dont get why you are suggesting that he needs to change it to else if.

Link to comment
Share on other sites

Also by looking at the code that last else statement is if this fails.

 

"move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)"

 

Its not linked to the the userid checsk. so I dont get why you are suggesting that he needs to change it to else if.

 

I did wonder that, Cheers for the help guys ill take a fresh look at it later

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.