sacl02 Posted June 12, 2013 Share Posted June 12, 2013 (edited) hi, /* $html .= ' <h2>'.$this->displayName.'</h2> <form action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" method="post"> <fieldset> <p><label for="num_id">'.$this->l('Indique o seu ID').' :</label><input type="text" id="num_id" name="ID"/> <input " type="submit" name="submitModule" value="'.$this->l('Update settings').'" class="button" /></center></p> </fieldset> </form> '; With that form how can i sent the id_num to prestashop database? My module already create the table during the install. this code is for back-office of prestashop Edited June 12, 2013 by vekia (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 12, 2013 Share Posted June 12, 2013 in the module body, for example in the function where you display the form, use something like: if ($_POST['submitModule']){ sql query here (via Db object) } Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 Somethig like this : if ($_POST['submitModule']){ $sql="INSERT INTO ID_table (app_id) VALUES ('$_POST[iD]')"; Link to comment Share on other sites More sharing options...
vekia Posted June 12, 2013 Share Posted June 12, 2013 so, this method works for you? (remember to use Db object to run your queries!) Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) where is the exactly place to put the code? Edited June 12, 2013 by sacl02 (see edit history) Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) if ($_POST['submitModule']) { Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'ID` (app_id) VALUES ("$_POST[id]")'); } thats works , but is not register the ID, it register the "$_POST[id]", could be because i use the "" or ' ' on the wrong way Edited June 12, 2013 by sacl02 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 12, 2013 Share Posted June 12, 2013 you can use this: {$_POST['id']} and this is correct code. Why? check php error log, you've got probably notification about wrong index in $_POST variable i marked this thread as [solved] regards! Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 That's the right way if ($_POST['submitModule']) { Db::getInstance()->execute("INSERT INTO `"._DB_PREFIX_."ID` (app_id) VALUES ('$_POST[iD]')"); } Link to comment Share on other sites More sharing options...
vekia Posted June 12, 2013 Share Posted June 12, 2013 yes, everything looks fine, but: $_POST[iD] - this is wrong method, i know that it works, but that is not compliant with php standards. Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 so, What I have to do? yes, everything looks fine, but: $_POST[iD] - this is wrong method, i know that it works, but that is not compliant with php standards. Link to comment Share on other sites More sharing options...
sacl02 Posted June 12, 2013 Author Share Posted June 12, 2013 (edited) AS you can see in the picture, when i refresh the back-office page it will register the same id over and over again...that table it's just to have one register. how can i fix that? Edited June 12, 2013 by sacl02 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 12, 2013 Share Posted June 12, 2013 make query to database SELECT * from TABLE where app_id='YOUR_APP_ID' if you haven't got this row in $result - add it to table, if you've got - do nothing Link to comment Share on other sites More sharing options...
sacl02 Posted June 14, 2013 Author Share Posted June 14, 2013 I will try that later, now i have another problem to fix. echo "<script>"; echo "var app_appid = 'e8ad9b1';"; echo "</script>"; echo "<script src='' type='text/javascript' language='JavaScript'></script>"; this is a javascript code in php file. How can i get the 'e8ad9b1' from database prestashop? echo "var app_appid = 'e8ad9b1';"; example echo "var app_appid = '$_POST[iD]';"; Link to comment Share on other sites More sharing options...
vekia Posted June 14, 2013 Share Posted June 14, 2013 you've got it in database? if so: where? In the ps_configuration table? Link to comment Share on other sites More sharing options...
sacl02 Posted June 14, 2013 Author Share Posted June 14, 2013 When i install the module create a table in prestashop . the code: public function installDB() { DB::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ID_test` ( `num_id` int(10) unsigned NOT NULL auto_increment, `app_id` varchar(255) NOT NULL, PRIMARY KEY (`num_id`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); return true; } Link to comment Share on other sites More sharing options...
vekia Posted June 14, 2013 Share Posted June 14, 2013 and you've got this variable in this database? you want to store in this table many rows? if not, it's better to use Configuration object Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now