Page 1 of 1

update/insert query failing to save to database in J1.5

Posted: Wed Jan 16, 2008 11:48 am
by ewel
I am trying to convert a module to Joomla 1.5 and running into a bit of trouble. I can see that most of my code works, but when it comes to saving to the database it fails.

The relevant bit of code in issue is the following - in which $dbtext is what already exists in the database (works), if anything, $newtext is obtained from JRequest::getVar('newtext') (works), and $usrid is taken from $user = &JFactory::getUser(); $usrid = $user->get('id'); (also works).

Code: Select all

if($dbtext) {
   $query = "UPDATE #__mytext SET text = '".$newtext."' WHERE id = ".$usrid;
   $db->setQuery($query);
   $db->query();
} else {
   $query = "INSERT INTO #__mytext (id,text) VALUES ('".$usrid."','".$newtext."')";
   $db->setQuery($query);
   $db->query();
}


Looking around I found information about JTable but I have to admit that I just do not understand what to do with it.

Would anyone be able to tell me if I made some mistake or how I should do this differently? Please do tell me if the above code is not enough to help.


UPDATE: Solved it after reading another post somewhere. Turns out that the code to create a table missed $db->query(); after $db->setQuery($query);.
I'd still like to find a good starters resource on working with the database in J1.5. I have seen that there is lots of information but I think I am missing the first few steps on the ladder.