Jump to content


Photo

A Very Quick Question


  • Please log in to reply
15 replies to this topic

#1 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 19 July 2006 - 07:19 PM

Hi,

Just a quick question. which Im sure one of you can answer very quickly.

My code
<?PHP

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}

$target = "rosco/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is the size condition
if ($uploaded_size > 100) {
$errorMsg = $lang['front']['upload']['error_filesize'];
$ok=0;

//This is the type condition
} elseif (!($uploaded_type=="image/gif")) {
$errorMsg = $lang['front']['upload']['error_filetype'];
$ok=0;

//Here we check that $ok was not set to 0 by an error
} elseif ($ok==0) {
$errorMsg = $lang['front']['upload']['upload_failed'];

} else {

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

$upload = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/upload.tpl");

	$upload->assign("LANG_UPLOAD_TITLE",$lang['front']['upload']['upload_title']);
	
	if(isset($ok) == 1) {
		$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_success']);
		$upload->parse("upload.session_true.no_error");
	} elseif(isset($errorMsg)) {
		$upload->assign("VAL_ERROR",$errorMsg);
		$upload->parse("upload.session_true.error");
	} else {
		$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_description']);
		$upload->parse("upload.session_true.no_error");
	}
	

	if($ccUserData[0]['customer_id']>0) {
		
		$upload->parse("upload.session_true");
	
	} else { 
		$upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
		$upload->parse("upload.session_false");
	
	
}
}

	$upload->parse("upload");
$page_content = $upload->text("upload");
?>

The error
Parse error: syntax error, unexpected $end in /home/semperfi/public_html/cubecartservices/includes/content/upload.inc.php on line 88

Any help getting this fixed would be greatly appreciated :)

#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 19 July 2006 - 07:25 PM

Errr... There are no includes, no requires, no $end variable, and its less then 88 lines long.

Is this even the right script?!
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 19 July 2006 - 07:47 PM

you're missing a closing brace ( } ).  you are not closing the overall else{} statement that encases the rest of the file.  add another brace to the set of two near the bottom of your file.

#4 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 19 July 2006 - 11:44 PM

Thanks akitchin :)

I added the extra } as you suggested.
Now I get a "Fatal error: Call to a member function on a non-object on line 86"

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 July 2006 - 11:47 PM

Which line is 86?

#6 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 19 July 2006 - 11:49 PM

Which line is 86?


Errr... There are no includes, no requires, no $end variable, and its less then 88 lines long.


it is also less then 86 lines long. Its a syntax error somewhere in there creating an odd error.
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#7 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 20 July 2006 - 12:35 AM

Sorry for the lack of info, been back and forth all day.

The code above is from a file called upload.inc.php

Its called via index.php with this:
case "upload":
				include("includes/content/upload.inc.php");
				$body->assign("PAGE_CONTENT",$page_content);
			break;

And as you can see, the html side of things is handled by upload.tpl

As for what line 86 is, that would be :
74	if($ccUserData[0]['customer_id']>0) {
75		
76		$upload->parse("upload.session_true");
77	
78	} else { 
79		$upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
80		$upload->parse("upload.session_false");
81	
82	
83 }
84 }
85 }
86 	$upload->parse("upload");
87 $page_content = $upload->text("upload");
88 ?>


#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 01:41 AM



I dont know but is the page upload.php or upload.inc?

include("includes/content/upload.inc.php");

one or the other i think like i say dont know why sorry.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 20 July 2006 - 05:47 AM

what does the entire parse error say?  usually it should be easy to figure out a function call on a non-object, since i think it says which variable you're trying to call a member function.

either way, what it means is that an object you're calling a method from hasn't been initialized properly, or it's been differently named, etc.  the full parse error will help in tracking down where it is and which file it's from.

#10 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 July 2006 - 12:43 PM

The page would be upload.inc.php
Whilst accessed via a browser it would be more like index.php?act=upload

The rest of the error message is :
Fatal error: Call to a member function on a non-object in /includes/content/upload.inc.php on line 86

#11 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 21 July 2006 - 02:52 PM

it's because you're calling a method on $upload OUTSIDE of the else{} statement - this will fail if the move_uploaded_file() if() condition fails, because you're only calling the object from within that branch.  if you don't execute that branch, $upload will never have been created.

#12 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 July 2006 - 03:51 PM

Ok, so at least the cause has been found.
Any ideas on a possible solution?

#13 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 21 July 2006 - 03:59 PM

Perhaps...

<?PHP

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}

$target = "rosco/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;

//This is the size condition
if ($uploaded_size > 100) {
$errorMsg = $lang['front']['upload']['error_filesize'];
$ok=0;

//This is the type condition
} elseif (!($uploaded_type=="image/gif")) {
$errorMsg = $lang['front']['upload']['error_filetype'];
$ok=0;

//Here we check that $ok was not set to 0 by an error
} elseif ($ok==0) {
$errorMsg = $lang['front']['upload']['upload_failed'];

} else {

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

$upload = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/upload.tpl");

	$upload->assign("LANG_UPLOAD_TITLE",$lang['front']['upload']['upload_title']);
	
	if(isset($ok) == 1) {
		$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_success']);
		$upload->parse("upload.session_true.no_error");
	} elseif(isset($errorMsg)) {
		$upload->assign("VAL_ERROR",$errorMsg);
		$upload->parse("upload.session_true.error");
	} else {
		$upload->assign("LANG_UPLOAD_DESCRIPTION",$lang['front']['upload']['upload_description']);
		$upload->parse("upload.session_true.no_error");
	}
	

	if($ccUserData[0]['customer_id']>0) {
		
		$upload->parse("upload.session_true");
	
	} else { 
		$upload->assign("LANG_LOGIN_REQUIRED",$lang['front']['upload']['login_required']);
		$upload->parse("upload.session_false");
	}

             $upload->parse("upload");
             $page_content = $upload->text("upload");
} else {
             // Error message. Upload failed
             die("Error Uploading!");
}

?>


#14 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 21 July 2006 - 04:15 PM

Thanks for the reply HeyRay2 :)

Before I try that, here is an example of an include file that does work

<?php
/*
+--------------------------------------------------------------------------
|   CubeCart v3.0.10
|   ========================================
|   by Alistair Brookbanks
|	CubeCart is a Trade Mark of Devellion Limited
|   Copyright Devellion Limited 2005 - 2006. All rights reserved.
|   Devellion Limited,
|   22 Thomas Heskin Court,
|   Station Road,
|   Bishops Stortford,
|   HERTFORDSHIRE.
|   CM23 3EE
|   UNITED KINGDOM
|   http://www.devellion.com
|	UK Private Limited Company No. 5323904
|   ========================================
|   Web: http://www.cubecart.com
|   Date: Tuesday, 14th March 2006
|   Email: info (at) cubecart (dot) com
|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 
|   Licence Info: http://www.cubecart.com/site/faq/license.php
+--------------------------------------------------------------------------
|	profile.inc.php
|   ========================================
|	Customers Profile	
+--------------------------------------------------------------------------
*/

if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}

// send email if form is submit
if(isset($_POST['submit']) && $ccUserData[0]['customer_id']>0){

	if($_POST['email']!==$ccUserData[0]['email']){
		$emailArray = $db->select("SELECT customer_id, type FROM ".$glob['dbprefix']."CubeCart_customer WHERE email=".$db->mySQLSafe($_POST['email']));
	}

	if(empty($_POST['firstName']) || empty($_POST['lastName']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['add_1']) || empty($_POST['town']) || empty($_POST['county']) || empty($_POST['postcode']) || empty($_POST['country']) || empty($_POST['companyName']) || empty($_POST['siteURL'])){
	
	$errorMsg = $lang['front']['profile']['complete_all'];
	
	} elseif(validateEmail($_POST['email'])==FALSE) {
	
	$errorMsg = $lang['front']['profile']['email_invalid'];
	
	} elseif(!ereg("[0-9]",$_POST['phone'])) {
	
	$errorMsg = $lang['front']['profile']['enter_valid_tel'];
	
	} elseif(!empty($_POST['mobile']) && !ereg("[0-9]",$_POST['mobile'])) {
	
	$errorMsg = $lang['front']['profile']['enter_valid_tel'];
	
	} elseif(isset($emailArray) && $emailArray == TRUE && $emailArray[0]['type']==1) {
	
	$errorMsg = $lang['front']['profile']['email_inuse'];
	
	} else {
		
		// update database
			$data['title'] = $db->mySQLSafe($_POST['title']);
			$data['firstName'] = $db->mySQLSafe($_POST['firstName']);
			$data['lastName'] = $db->mySQLSafe($_POST['lastName']); 
			$data['email'] = $db->mySQLSafe($_POST['email']); 
			$data['add_1'] = $db->mySQLSafe($_POST['add_1']);
			$data['add_2'] = $db->mySQLSafe($_POST['add_2']);
			$data['town'] = $db->mySQLSafe($_POST['town']); 
			$data['county'] = $db->mySQLSafe($_POST['county']); 
			$data['postcode'] = $db->mySQLSafe($_POST['postcode']);
			$data['country'] = $db->mySQLSafe($_POST['country']);
			$data['phone'] = $db->mySQLSafe($_POST['phone']); 
			$data['mobile'] = $db->mySQLSafe($_POST['mobile']);
			$data['companyName'] = $db->mySQLSafe($_POST['companyName']);
			$data['siteURL'] = $db->mySQLSafe($_POST['siteURL']);
			
					// look up users zone
			$zoneId = $db->select("SELECT * FROM ".$glob['dbprefix']."CubeCart_iso_counties WHERE (abbrev LIKE '".addslashes_gpc($_POST['county'])."' OR name LIKE '".addslashes_gpc($_POST['county'])."')");
		
			if($zoneId[0]['id']>0){
		
				$data["zoneId"] = $zoneId[0]['id'];
		
			} else {
			
				$data["zoneId"] = 0;
				
			} 
	
			$where = "customer_id = ".$ccUserData[0]['customer_id'];
			$updateAcc = $db->update($glob['dbprefix']."CubeCart_customer",$data,$where);
			
					// make email
			include("classes/htmlMimeMail.php");
			
			$mail = new htmlMimeMail();
			
			$text = sprintf($lang['front']['profile']['update_email'],$_POST['firstName'],$_POST['lastName'],$GLOBALS['storeURL'],$_SERVER['REMOTE_ADDR']);
			
			$mail->setText($text);
			$mail->setFrom($config['masterName'].' <'.$config['masterEmail'].'>');
			$mail->setSubject($lang['front']['profile']['update_email_subj']);
			$mail->setHeader('X-Mailer', 'CubeCart Mailer');
			$send = $mail->send(array($_POST['email']), $config['mailMethod']);
			
			if(isset($_GET['f']) && !empty($_GET['f'])){
				header("Location: cart.php?act=".$_GET['f']);
			}
	
			// rebuild customer array
			$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_sessions INNER JOIN ".$glob['dbprefix']."CubeCart_customer ON ".$glob['dbprefix']."CubeCart_sessions.customer_id = ".$glob['dbprefix']."CubeCart_customer.customer_id WHERE sessId = '".$_SESSION['ccUser']."'";
			$ccUserData = $db->select($query);
	}
}

$profile = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/profile.tpl");

	$profile->assign("LANG_PERSONAL_INFO_TITLE",$lang['front']['profile']['personal_info']);
	
	if(isset($updateAcc) && $updateAcc == TRUE) {
		$profile->assign("LANG_PROFILE_DESC",$lang['front']['profile']['account_updated']);
		$profile->parse("profile.session_true.no_error");
	} elseif(isset($errorMsg)) {
		$profile->assign("VAL_ERROR",$errorMsg);
		$profile->parse("profile.session_true.error");
	} else {
		$profile->assign("LANG_PROFILE_DESC",$lang['front']['profile']['edit_below']);
		$profile->parse("profile.session_true.no_error");
	}
	
	if($ccUserData[0]['customer_id']>0) { 
	
		if(isset($_GET['f']) && !empty($_GET['f'])){
		$profile->assign("VAL_EXTRA_GET","&amp;f=".$_GET['f']);
		}
	
		$profile->assign("TXT_TITLE",$lang['front']['profile']['title']);
		$profile->assign("VAL_TITLE",$ccUserData[0]['title']);
		
		$profile->assign("TXT_FIRST_NAME",$lang['front']['profile']['first_name']);
		$profile->assign("VAL_FIRST_NAME",$ccUserData[0]['firstName']);
		
		$profile->assign("TXT_LAST_NAME",$lang['front']['profile']['last_name']);
		$profile->assign("VAL_LAST_NAME",$ccUserData[0]['lastName']);
		
		$profile->assign("TXT_EMAIL",$lang['front']['profile']['email']);
		$profile->assign("VAL_EMAIL",$ccUserData[0]['email']);
		
		$profile->assign("TXT_ADD_1",$lang['front']['profile']['address']);
		$profile->assign("VAL_ADD_1",$ccUserData[0]['add_1']);
		
		$profile->assign("TXT_ADD_2","");
		$profile->assign("VAL_ADD_2",$ccUserData[0]['add_2']);
		
		$profile->assign("TXT_TOWN",$lang['front']['profile']['town']);
		$profile->assign("VAL_TOWN",$ccUserData[0]['town']);
		
		$profile->assign("TXT_COUNTY",$lang['front']['profile']['county']);
		$profile->assign("VAL_COUNTY",$ccUserData[0]['county']);
		
		$profile->assign("TXT_POSTCODE",$lang['front']['profile']['postcode']);
		$profile->assign("VAL_POSTCODE",$ccUserData[0]['postcode']);
		
		$profile->assign("TXT_COUNTRY",$lang['front']['profile']['country']);
		

	$countries = $db->select("SELECT id, printable_name FROM ".$glob['dbprefix']."CubeCart_iso_countries ORDER BY printable_name"); 
	
	for($i=0; $i<count($countries); $i++){

			
				if($countries[$i]['id'] == $ccUserData[0]['country']){
					$profile->assign("COUNTRY_SELECTED","selected='selected'");
				} else {
					$profile->assign("COUNTRY_SELECTED","");
				}
			
				$profile->assign("VAL_COUNTRY_ID",$countries[$i]['id']);
		
				$countryName = "";
				$countryName = $countries[$i]['printable_name'];
		
				if(strlen($countryName)>20){
		
					$countryName = substr($countryName,0,20)."&hellip;";
		
				}
		
				$profile->assign("VAL_COUNTRY_NAME",$countryName);
				
				$profile->parse("profile.session_true.country_opts");
			
			} 
	
		$profile->assign("VAL_COUNTRY",$ccUserData[0]['country']);
		
		$profile->assign("TXT_PHONE",$lang['front']['profile']['phone']);
		$profile->assign("VAL_PHONE",$ccUserData[0]['phone']);
		
		$profile->assign("TXT_MOBILE",$lang['front']['profile']['mobile']);
		$profile->assign("VAL_MOBILE",$ccUserData[0]['mobile']);

		$profile->assign("TXT_COMPANYNAME",$lang['front']['profile']['companyname']);
		$profile->assign("VAL_COMPANYNAME",$ccUserData[0]['companyName']);

		$profile->assign("TXT_SITEURL",$lang['front']['profile']['siteurl']);
		$profile->assign("VAL_SITEURL",$ccUserData[0]['siteURL']);
		
		$profile->assign("TXT_SUBMIT",$lang['front']['profile']['update_account']);

		$profile->parse("profile.session_true");
	
	} else { 
		$profile->assign("LANG_LOGIN_REQUIRED",$lang['front']['profile']['login_required']);
		$profile->parse("profile.session_false");
	
	}
	
	$profile->parse("profile");
$page_content = $profile->text("profile");
?>



#15 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 23 July 2006 - 11:59 PM

Any further suggestions  ???

#16 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 28 July 2006 - 01:57 PM

The working code example you mention calls a method on an object ($Profile) regardless of whether or not a form has been submitted.

Your code will fail with the "method on a non-object" if the following conditional is false:

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

This is because the $upload object will not be defined in this case. You need to ensure that you don't make calls on $upload if you have not defined it. That's what my code change does for you. The only part of your code I changed is the last 5 lines from:

}
}

	$upload->parse("upload");
$page_content = $upload->text("upload");

to:

             $upload->parse("upload");
             $page_content = $upload->text("upload"); 
   } else {
             // Error message. Upload failed
             die("Error Uploading!");
   }

}

Did you try my change? Did it make any difference?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users