Jump to content

Problem with insert in new Table


Recommended Posts

Hi guys,


i have created manually (from the sql window of my PHPMYADMIN) a new table named 'pst_horaire'

like this 




the problem i have that where i want to insert a new line from a customized controller  i have created , the insertion fails and  i don't know why 


this is how i try to insert in the table

$difference = Tools::getValue("diffdays");
   			for ($i=0; $i <=$difference ; $i++) 
   				$debut = Tools::getValue("horaire_debut_".$i);
				$fin = Tools::getValue("horaire_fin_".$i);
				$date_formation = Tools::getValue("date_day_".$i);
				$res=Db::getInstance()->insert("horaire", array(
						'horaire_debut' => 'salut',
						'horaire_fin' => 'bye',
						'date_day' => '2013-09-11 10:44:51',
						'id_product' => 20,
						'id_seller' => 21,
				echo 'ok';
					echo 'not ok';

can anyone help me to fix this please ?

Share this post

Link to post
Share on other sites

have you got any error message? what you've got in result in $res variable?


try with simple query:

Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'horaire` (FIELDS HERE) VALUES (VALUES HERE)');


of course define fields and values

Share this post

Link to post
Share on other sites

Thank you Vekia i fixed it the issue was in my Class Horaire.php in the validator of my id_product 

class Horaire extends ObjectModel 
  /** @var string Name */
  public $horaire_debut;
  /** @var string Name */
  public $horaire_fin;
  /** @var string formationdate */
	public $date_day;

  /** @var integer seller id */
	public $id_seller;
	/** @var integer product id */
	public $id_product;
		public static $definition = array(
		'table' => 'horaire',
		'primary' => 'id_horaire',
		'multilang' => true,
		'multilang_shop' => true,
		'fields' => array(
			'horaire_debut' => 				array('type' => self::TYPE_STRING, 'validate' => 'isHoraireDebut', 'size' => 10),
			'horaire_fin' => 				array('type' => self::TYPE_STRING, 'validate' => 'isHoraireFin', 'size' => 10),
			'date_day' => 					array('type' => self::TYPE_STRING, 'validate' => 'isDateDay', 'size' => 30),
			'id_seller' => 					array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
			'id_product' => 					array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),

  public function getFields() 
    $fields['horaire_debut'] = pSQL($this->horaire_debut);
	$fields['horaire_fin'] = pSQL($this->horaire_fin);
	$fields['date_day'] = $this->date_day;
	$fields['id_seller'] = $this->id_seller;
	$fields['id_product'] = $this->id_product;
    return $fields;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More