简体   繁体   中英

How to insert value in Joomla1.5 own created Module

I am new in Joomla , i want to insert value by my own module in database in my own table my module helper class look like

// no direct access defined('_JEXEC') or die('Restricted access'); 
class modmyModuleHelper 
{ 
   function getHello($params)
   {         
       echo $track_code=$_REQUEST['track_code'];
       $sql="insert into jos_ trackno values($track_code)";
       mysql_query($sql);
       $x="<form>Enter Code<input type='text' name='track_code'>
       <input type='submit' name='go' value='GO'></form>";

       //return $sql;           
       return $x; 
   }    
}

Firstly, I would not name function for inserting to database getHello , but rather insertHello .

Secondly, use inserting function for this purpose only, don't return some HTML code. Return boolean value and decide later what to display.

I would use something like this:

class modmyModuleHelper {

    function insertTrackCode() {
        if (!empty($_REQUEST['track_code'])) {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query
                ->insert($db->quoteName('#__trackno'))
                ->values($_REQUEST['track_code']);
            $db->setQuery($query);
            return $db->query();
        } else {
            return false;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM