[FX.php List] calling a function not working

Erik Andreas Cayré erik at cayre.dk
Wed Oct 25 16:47:45 MDT 2006


Den 25/10/2006 kl. 18.54 skrev Derrick Fogle:

> Your reference to server_data.php is not working

Right.

When referring to variables inside a php function, which are defined  
outside that function, you must use 'global ($variable)'

like so:

// initialize system parameters
	function initsystem () {
		global $fmshost;
		global $dataport;
		global $dbname;
		global $user;
		global $pass;
		$fx = new FX($fmshost, $dataport);
		$fx->SetDBData($dbname, 'system');
		$fx->SetDBUserPass($user, $pass);
		$return_data = $fx->FMFindall();
		
		// Transform FM data into more useful array
		if ($return_data['errorCode'] == 0) {
			$_SESSION['system'] = array();

			foreach ($return_data['data'] AS $fmrec => $fmrecord) {
				foreach ($fmrecord as $fieldname => $value) {
					if (!empty($value)) {
						if (count($value) != 1) {
							$_SESSION['system'][$fieldname] = $value;
						} else {
							$_SESSION['system'][$fieldname] = $value['0'];
						}
					}
				}
			}
			if (empty($_SESSION['system'])) {
				die('fatal system error');
			}
		}

		return;
	}

/eac

> On Oct 25, 2006, at 11:50 AM, David Tinoco wrote:
>
>> Hi Guys,
>>
>> I created 2 php files. One is called additem and contains a  
>> function called additem().
>>
>> I am trying to call this function from another page.
>>
>> Here is the additem page:
>>
>> <?php
>>
>> session_start();
>> include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/FX.php");
>> include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/server_data.php");
>>
>> function additem($item,$quantity)
>> {
>> $finditem= '=='.$item;
>> ##If an order number already exists (an item has already been added.)
>> if(isset($_SESSION['ordno'])){
>> ##Check to see if the item is already on the order.
>> $checkitem=new FX($serverIP,$webCompanionPort);
>> $checkitem->SetDBData('XXXXXX.fp7','Order Items');
>> $checkitem->SetDBPassword($webPW,$webUN);
>> $checkitem->AddDBParam('LinkOrder',$_SESSION['ordno']);
>> $checkitem->AddDBParam('Item',$finditem);
>> $checkitemResult=$checkitem->FMFind();
>> foreach($checkitemResult['data']as $key=>$checkitemData);
>> $checkitemCount = $checkitemResult['foundCount'];
>> ##If so, update the qty, do not create a new record.
>> if ($checkitemCount > 0){
>> $newamount = $checkitemData['OriginalQty'][0] + $quantity;
>> $newitem=new FX($serverIP,$webCompanionPort);
>> $newitem->SetDBData('XXXXXX.fp7','Order Items');
>> $newitem->SetDBPassword($webPW,$webUN);
>> $newitem->AddDBParam('OriginalQty',$newamount);
>> $newitem->AddDBParam('-recid',$checkitemData['Line_ID'][0]);
>> $newitemResult=$newitem->FMEdit();
>> foreach($newitemResult['data']as $key=>$newitemData);
>> $resultupc = $newitemData['Item'][0];
>> }
>> ##If there is no item in the cart, create the item.
>> elseif ($checkitemCount == 0){
>> $newitem=new FX($serverIP,$webCompanionPort);
>> $newitem->SetDBData('XXXX.fp7','Order Items');
>> $newitem->SetDBPassword($webPW,$webUN);
>> $newitem->AddDBParam('LinkOrder',$_SESSION['ordno']);
>> $newitem->AddDBParam('Item',$item);
>> $newitem->AddDBParam('OriginalQty',$quantity);
>> $newitemResult=$newitem->FMNew();
>> foreach($newitemResult['data']as $key=>$newitemData);
>> $resultupc = $newitemData['Item'][0];
>> $_SESSION['item']=$newitemData['Item'][0];
>> }
>> }
>> ##If order number does not exist, safe to create a new order and  
>> add the item.
>> else{
>> $neworder=new FX($serverIP,$webCompanionPort);
>> $neworder->SetDBData('XXXX.fp7','TempOrders');
>> $neworder->SetDBPassword($webPW,$webUN);
>> $neworderResult=$neworder->FMNew();
>> foreach($neworderResult['data']as $key=>$neworderData);
>> $_SESSION['ordno']=$neworderData['k_Session ID'][0];
>> $newitem=new FX($serverIP,$webCompanionPort);
>> $newitem->SetDBData('XXXXXX.fp7','Order Items');
>> $newitem->SetDBPassword($webPW,$webUN);
>> $newitem->AddDBParam('LinkOrder',$neworderData['k_Session ID'][0]);
>> $newitem->AddDBParam('Item',$item);
>> $newitem->AddDBParam('OriginalQty',$quantity);
>> $newitemResult=$newitem->FMNew();
>> foreach($newitemResult['data']as $key=>$newitemData);
>> $resultupc = $newitemData['Item'][0];
>> $_SESSION['item']=$newitemData['Item'][0];
>> }
>> }
>> ?>
>> ________________________
>>
>> From a page that shows products in a catalog, the user click add  
>> to cart which takes them to the second page, viewcart.php from a  
>> form which has this in it:
>> <a href="viewcart.php?additem=1&item=10835&qty=3">Add to Cart</a>
>>
>> Viewcart has this in it:
>>
>> if(isset($_REQUEST['additem']))
>> {
>> $upc=$_REQUEST['item'];
>> $amount=$_REQUEST['qty'];
>> additem($upc,$amount);
>> }
>>
>> This viewcart has the include_once for the FX errors, FX.php and  
>> server_data page and include_once for the additem.php page.  
>> However, the error returned by PHP is that the FX variables do not  
>> exist ($serverIP, $webPW, etc.)
>>
>>
>> Notice: Undefined variable: serverIP in c:\Inetpub\wwwroot 
>> \viewcart.php on line 51
>>
>> Notice: Undefined variable: webCompanionPort in c:\Inetpub\wwwroot 
>> \viewcart.php on line 51
>>
>> Notice: Undefined variable: webPW in c:\Inetpub\wwwroot 
>> \viewcart.php on line 53
>>
>> Notice: Undefined variable: webUN in c:\Inetpub\wwwroot 
>> \viewcart.php on line 53
>>
>> Fatal error: Cannot use object of type FX_Error as array in c: 
>> \Inetpub\wwwroot\viewcart.php on line 55
>>
>> Anyone know what I am doing wrong?
>>
>> Thanks,
>> David
>>
>> Try the next generation of search with Windows LiveT Search today!  
>> Try it now!
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
> Derrick Fogle
> derrick at fogles.net
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



---
Erik Andreas Cayré, IT Chef
Grafisk Trykcenter AS
Niels Lambertsens vej 6
6705 Esbjerg Ø

Direkte: 76 10 91 43
Fax: 76 10 91 11

---
»Kun p....sure mennesker kan ændre verden. Innovation skabes ikke af  
'markedsanalyse', men af folk, der er afsindigt irriterede over  
tingenes tilstand «
--Tom Peters

»Hvis du ikke kan forklare det simpelt, forstår  du det ikke godt nok.«
-- Albert Einstein

»Hvis du ikke har tid til at gøre det rigtigt, hvornår vil du så have  
tid til at lave det om?«
-- John Wooden, basketball coach


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1856 bytes
Desc: not available
Url : http://www.iviking.org/pipermail/fx.php_list/attachments/20061026/8ce7f839/smime-0001.bin


More information about the FX.php_List mailing list