RE: [PEAR] QuickForm with DB problem

From: Date: Sat, 19 Nov 2005 17:58:57 +0000
Subject: RE: [PEAR] QuickForm with DB problem
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22008@lists.php.net to get a copy of this message
I have a config file that I use to setup my DB connection. What I do, and I don't know if this is a good way or not but I pass my $db resource in and access it by reference. You can do this by adding a & in front of the variable when you declare your function. e.g. function display_form( &$db ) { $res =& $db->query("SELECT * from table"); } >-----Original Message----- >From: l Burnerheimerton [mailto:lburnerheimerton@yahoo.com] >Sent: Saturday, November 19, 2005 2:14 AM >To: pear-general@lists.php.net >Subject: [PEAR] QuickForm with DB problem > >I copied this form form a working form page. Now it throws an >error. Here's the code: > >if ($form->validate()) { > $form->process('process_data', false); > header("Location: nextpage.htm"); > exit; >} >function process_data ($v) { > // connection string > $table_name = 'registration'; > $table_fields = array(...); > $table_values = array(...); > $sth = $db->autoPrepare($table_name, $table_fields, >DB_AUTOQUERY_INSERT); > $res =& $db->execute($sth, $table_values); } $form->display(); > >The error is: >"Call to a member function on a non-object in ... line 72" >which is the following line from the above code: >$sth = $db->autoPrepare($table_name, $table_fields, >DB_AUTOQUERY_INSERT); > >I assume that means $db is not "visible" in that function. I >have added print_r($db) inside the function process_data and >it shows "Undefined >variable: db". I added "require_once("DB.php");" >inside the function and it still showed undefined variable. > >I used print_r($db) in the form part of the page and it >displays the $db array properly. But it somehow is not >working inside the function to process_data. I have verified >the DB.php and Connection string works. > >Any ideas? > > > >__________________________________ >Yahoo! FareChase: Search multiple travel sites in one click. >http://farechase.yahoo.com > >-- >PEAR General Mailing List (http://pear.php.net/) To >unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.pear.general (#22008) next »