Re: QuickForm with DB problem

From: Date: Sun, 20 Nov 2005 05:04:42 +0000
Subject: Re: QuickForm with DB problem
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22014@lists.php.net to get a copy of this message
On 11/19/05, l Burnerheimerton <lburnerheimerton@yahoo.com> 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. > functions don't inherit the scope of their parents. i.e. you have to define or "import" $db somehow. That function could not have been working in the way that you wrote it above. Ever. > 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? > So where is your db object? Perhaps you need to use $GLOBALS['db']? -- Justin Patrin

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