deansaddigh Posted June 23, 2009 Share Posted June 23, 2009 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/ Share on other sites More sharing options...
Jibberish Posted June 23, 2009 Share Posted June 23, 2009 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861853 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 the else statement is wrong you must convert some of it to elseif at line 66 to line 84 Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861854 Share on other sites More sharing options...
deansaddigh Posted June 23, 2009 Author Share Posted June 23, 2009 the else statement is wrong you must convert some of it to elseif at line 66 to line 84 The closing if statment bracket is right at the end m8 Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861857 Share on other sites More sharing options...
deansaddigh Posted June 23, 2009 Author Share Posted June 23, 2009 I h the else statement is wrong you must convert some of it to elseif at line 66 to line 84 The closing if statment bracket is right at the end mate Hi, i have tried that and it seems to still have no effect, im still getting the parse error Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861859 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 if using elseif you must do elseif(command("defined")) { } Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861861 Share on other sites More sharing options...
Jibberish Posted June 23, 2009 Share Posted June 23, 2009 What is the parse error? did you put the missing bracket in? Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861862 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 There is no missing bracket that is // else wont work if there are two else like if (command("defined")) { } else { } else { } You Should Do if (command("defined")) { } else { } elseif (command("defined")) { } Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861868 Share on other sites More sharing options...
Jibberish Posted June 23, 2009 Share Posted June 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861869 Share on other sites More sharing options...
deansaddigh Posted June 23, 2009 Author Share Posted June 23, 2009 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861870 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 WRONG Again... else if is only used after else statement is already used Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861871 Share on other sites More sharing options...
deansaddigh Posted June 23, 2009 Author Share Posted June 23, 2009 ok cheers. ill try and sort it out Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861875 Share on other sites More sharing options...
Adam Posted June 23, 2009 Share Posted June 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861877 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 I sort it out to be in elseif(command("wheretoberunn") { } works very fine for me Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861878 Share on other sites More sharing options...
Jibberish Posted June 23, 2009 Share Posted June 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861880 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 oh... its file upload... I have seem to encounter this... the problem is I dont need to use else I just use this if(!upload) { echo "Upload Failed"; } else { echo "Upload Successful"; } Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861883 Share on other sites More sharing options...
deansaddigh Posted June 23, 2009 Author Share Posted June 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/163350-parse-error-parse-error-in-process_avatar-line-84/#findComment-861886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.