Basic custom module with add feature

Hi
Is there any sample code for a basic custom module with a provision to add a record into database
Thanks

Hi, I have completed this. I have created inesrt and listing pages.

Great, anything to share to the community?

I am inserting name, email and address. Below is the code and we need to insert this in myobject.class.php available in class folder of mydemomodule

	function create($user='')
	{
		global $conf, $langs, $user;
		$langs->load('mydemomodule@mydemomodule');

		$error=0;

		//$this->code = trim($this->code);
		$this->name=(!is_array($this->name)?trim($this->name):'');
		$this->email=(!is_array($this->email)?trim($this->email):'');
		$this->address=(!is_array($this->address)?trim($this->address):'');

		$this->db->begin();

		$sql = "INSERT INTO ".MAIN_DB_PREFIX."mydemomodule_myobject (";
		$sql.= " name,";
		$sql.= " email,";
		$sql.= " address";
		$sql.= ") VALUES (";
		$sql.= " '".$this->db->escape($this->name)."'";
		$sql.= ", '".$this->db->escape($this->email)."'";
		$sql.= ", '".$this->db->escape($this->address)."'";
		$sql.= ")";
print $sql;
		dol_syslog(get_class($this).'::create sql='.$sql);
		if ($this->db->query($sql))
		{
			$rowid=$this->db->last_insert_id(MAIN_DB_PREFIX."mydemomodule_myobject");
			$this->db->commit();
			$this->rowid = $rowid;

			return $rowid;
		}
1 Like