Re: QuickForm with DB problem
| From: | Jens Kleikamp | Date: | Sat, 19 Nov 2005 13:27:29 +0000 |
| Subject: | Re: QuickForm with DB problem | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22004@lists.php.net to get a copy of this message | ||
l Burnerheimerton wrote:
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?Probably you created the db instance in the global variable scope. Try to set it global in the function before you use it. Checkout the global keyword which is documented here : http://php.net/global Hope that helps, Jens
__________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com