我有这个表格
<form method="post" action="{$urls.base_url|escape:'htmlall':'UTF-8'}index.php?fc=module&module=cdesigner&controller=storedata" id="form-submited">
<input type="hidden" name="link" id="cd-link">
<input type="hidden" name="id" id="cd-id">
<input type="hidden" name="output" id="cd-output">
<input type="hidden" name="pret" id="cd-pret" value="100">
</form>
和此storedata.php
class CdesignerStoredataModuleFrontController extends ModuleFrontController
{
public function init()
{
$this->page_name = 'storedata'; // page_name and body id
parent::init();
}
/** Init Function Controller **/
public function initContent()
{
parent::initContent();
if( !is_numeric(Tools::getValue('output')) )
exit();
$output = (int)Tools::getValue('output');
$pret = (int)Tools::getValue('pret'); // this is my edit
mysql_query("UPDATE ps_customized_data SET price=24 WHERE id_customization=82"); // until here
$link = filter_var(Tools::getValue('link'), FILTER_SANITIZE_SPECIAL_CHARS);
$html = filter_var(Tools::getValue('id'), FILTER_SANITIZE_SPECIAL_CHARS);
$myfile = fopen( dirname(__FILE__).'/../../views/img/files/tpl/tp_'.$output.'.html', "w") or die("Unable to open file!");
fwrite($myfile, $html);
fclose($myfile);
echo '
<script>
document.location = "'.$link.'";
</script>
';
exit();
}
}
我正在学习php,我不是专业人士。
我想用<input type="hidden" name="pret" id="cd-pret" value="100">
我认为我必须在storedata.php上调用sql
答案 0 :(得分:1)
要在Prestashop中执行SQL查询,应使用Best Practices of the Db Class。不要使用mysql_query
。
// Updating values
Db::getInstance()->update($table, $data, $where = '', $limit = 0, $null_values = false, $use_cache = true, $add_prefix = true)
以您的情况
$data = array(
'price' => $pret
);
Db::getInstance()->update('ps_customized_data', $data, 'id_customization = 82');