Joomla! Discussion Forums



It is currently Fri Nov 27, 2009 11:57 am (All times are UTC )

 




Post new topic Reply to topic  [ 15 posts ] 
Author Message
Posted: Wed Nov 04, 2009 5:21 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
I have some code that is supposed to insert into the joomla db:

Code:
SearchAdvancedHelper::saveSearch( 'test', '1');


Which calls the function:
Code:
function saveSearch( $search_string, $userID )
{
   $db =& JFactory::getDBO();

   $params = &JComponentHelper::getParams( 'com_searchadvanced' );
   $enable_saved_searches = $params->get('enable_save');

   //$search_term = $db->getEscaped( trim( $search_term) );

   if ( @$enable_saved_searches )
   {
      $db =& JFactory::getDBO();
      $query = 'INSERT INTO #__searchadvanced_saved_searches (user_id, search_string) VALUES ( "' . $userID .'", "'.$search_string.'" )';
      $db->setQuery( $query );
      $db->query();
      echo "DB: $query "; print_r($db->query); echo "<BR>";
   }
}


Which is being called because I get the echoed statement above, but nothing is entered into the DB.


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 5:55 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7691
Location: Europe
Why don't you use the insertObject method:
http://api.joomla.org/Joomla-Framework/ ... sertObject

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Wed Nov 04, 2009 6:25 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
I have this now...

Code:
$__data =new stdClass();
$__data->saved_search_id = null;
$__data->user_id = $userID;
$__data->search_string = $search_string;
$db = JFactory::getDBO();
$db->insertObject('#__searchadvanced_saved_searches', $__data, 'saved_search_id') ;
echo "DB: $query "; print_r($db->query); echo "<BR>";


But is still not inserting the information... is there a way to do an inline error check?


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 6:34 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
I added this code:

Code:
echo "ERROR: " . $db->getErrorNum() . "<BR>";


which returns an 1146 error. Researching this it means the table name is wrong, or prefixs in general. Adding the actual table name copied from the actual tablename in the insertObject function did not help.

Code:
$db->insertObject('jos_searchadvanced_saved_searches', $__data, 'saved_search_id') ;


And the prefix appears to be coorect in the config file..

var $dbprefix = 'jos_';


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 6:48 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
jntwebdesigns wrote:
I added this code:

Code:
echo "ERROR: " . $db->getErrorNum() . "<BR>";


which returns an 1146 error. Researching this it means the table name is wrong, or prefixs in general. Adding the actual table name copied from the actual tablename in the insertObject function did not help.

Code:
$db->insertObject('jos_searchadvanced_saved_searches', $__data, 'saved_search_id') ;


And the prefix appears to be coorect in the config file..

var $dbprefix = 'jos_';


Two things:
You have 2 underscores instead of one on the private variables. I don't know if that may be causing some glitch or not.

Re check the the number of arguments and type that the method requires. You will get odd results if all of this is not done properly. For instance, if the method will take 4 arguments and you use one of the optional ones, you need to put defaults or other optional data in the remaining arguments so they read in correctly.
Been there...


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 7:06 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7691
Location: Europe
Did you try to use this instead:

Code:
$db =& JFactory::getDBO();


Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Wed Nov 04, 2009 8:09 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
Changed to :

Code:
$__data =new stdClass();
$__data->saved_search_id = null;
$__data->user_id = $userID;
$__data->search_string = $search_string;
$db =& JFactory::getDBO();
$db->insertObject('#__searchadvanced_saved_searches', $__data, 'saved_search_id') ;
echo "DB: $query "; print_r($db->query); echo "<BR>";


Same result....


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 8:11 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7691
Location: Europe
What is your database structure?

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Wed Nov 04, 2009 8:23 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
What do you mean?
Do you mean the settings in the config, the DB type, or something else????


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 10:20 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
jntwebdesigns wrote:
What do you mean?
Do you mean the settings in the config, the DB type, or something else????


He means that the database structure, columms, length, type, etc need to match the $__data object EXACTLY.


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 10:37 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
`jos_searchadvanced_saved_searches` (
`saved_search_id` int(15) NOT NULL AUTO_INCREMENT,
`user_id` int(15) NOT NULL,
`search_string` varchar(255) NOT NULL,
PRIMARY KEY (`saved_search_id`)


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 10:50 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7691
Location: Europe
did you try this:

Code:
$db->insertObject('#__searchadvanced_saved_searches', $__data);


Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Thu Nov 05, 2009 12:31 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
same result.


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 9:54 am 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7691
Location: Europe
and you are sure the jos_searchadvanced_saved_searches table exists in the joomla database?

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Thu Nov 05, 2009 12:48 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Nov 02, 2009 4:22 pm
Posts: 18
okay, I feel really stupid. It turns out I had 2 joomla databases. Since I use this as a development site, there were tons of databases. I searched and there were 2 copies of Joomla running.

It works fine now.


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

Quick reply

 



Who is online

Users browsing this forum: DeanMarshall, Google [Bot], uglykidjoe and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group