I am making a custom module for Magento 1.7.0. I am facing a problem while trying to insert data into MySQL. I fetch the user information from the session as follows:
$customer = Mage::getSingleton('customer/session')->getCustomer();
$user_id = $customer->getId();
$user_id now carries ID of the current user logged into my Magento system.
Basically the problem is that when I try to save this above ID in my custom table, the value that is saved in my table is always 0.
Previously I faced this problem while trying to save another integer value, which I solved by changing the datatype of my MySQL table column from int(10) to tinyint(4), but in this case I cannot do so for the user ID.
$model= Mage::getModel('voter/competetion')
->setDesignid($designId)
->setUserId($user_id)
->setVote($vote)
->setStartdate($startDate)
->save();
The MySQL column name are as follows along with the install sql script: id, designid, user_id, vote, startdate, enddate
$installer = $this;
$installer->startSetup();
$prefix = Mage::getConfig()->getTablePrefix();
$installer->run("
CREATE TABLE IF NOT EXISTS ".$prefix."vote_competetion (
id int(10) NOT NULL AUTO_INCREMENT,
designid int(10) NOT NULL,
user_id int(10) NOT NULL,
vote tinyint(1) NOT NULL,
startdate datetime NOT NULL,
enddate datetime NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (designid) REFERENCES ".$prefix."vote_design(id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
");
Mage::getModel('core/url_rewrite')->setId(null);
$installer->endSetup();
Is there something wrong with my setter method name. All other values are being saved correctly. I am really not sure what to do about this. Please help.
I appreciate all the help.
Thanks!