【发布时间】:2021-05-10 21:34:41
【问题描述】:
来自希腊的问候,
我正在尝试将一些输入数据从位于 tpl 文件中的表单发布到我的数据库中的表中。
我正在尝试将一些输入数据从位于 tpl 文件中的表单发布到我的数据库中的表中。
我尝试了很多方法都没有成功。 (我是 prestashop 模块开发的新手)
提前感谢您的帮助。
我创建表单的文件是: 项目模块.tpl
<h4>{l s='Project Module' mod='projectmodule'}</h4>
<div class="separation"></div>
<form name="text_fields" method="post" action="">
<table>
<tr>
<td class="col-left">
<label>{l s='First Field:'}</label>
</td>
<td>
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_name='firstfield'
input_value=$firstfield}
<p class="preference_description"></p>
</td>
</tr>
<tr>
<td class="col-left">
<label>{l s='Second Field:'}</label>
</td>
<td>
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_name='secondfield'
input_value=$secondfield}
<p class="preference_description"></p>
</td>
</tr>
<tr>
<td class="col-left">
<label>{l s='Third Field:'}</label>
</td>
<td>
{include file="controllers/products/input_text_lang.tpl"
languages=$languages
input_name='thirdfield'
input_value=$thirdfield}
<p class="preference_description"></p>
</td>
</tr>
<tr>
<td><input type ="submit" name = "submit_form" value = "Submit" /></td>
</tr>
</table>
</form>
我的主要 php 文件是: 项目模块.php
public function install()
{
include(dirname(__FILE__).'/sql/install.php');
return parent::install() &&
$this->registerHook('displayAdminProductsExtra');
}
public function uninstall()
{
include(dirname(__FILE__).'/sql/uninstall.php');
return parent::uninstall();
}
public function prepareNewTab()
{
$this->context->smarty->assign(array(
'languages' => $this->context->controller->_languages,
));
}
public function hookDisplayAdminProductsExtra($params)
{
if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
{
$this->prepareNewTab();
return $this->display(__FILE__, 'projectmodule.tpl');
}
}
我在数据库中创建表的文件是:install.php
$sql = array();
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'projectmodule` (
`id_projectmodule` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id_projectmodule`),
`firstfield` varchar(255) NOT NULL,
`secondfield` varchar(255) NOT NULL,
`thirdfield` varchar(255) NOT NULL
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';
foreach ($sql as $query) {
if (Db::getInstance()->execute($query) == false) {
return false;
}
}
【问题讨论】:
-
“没有任何成功”不是很充分。你做了什么?您是否检查过浏览器控制台是否有错误?您检查过网络服务器错误日志吗?您是否查看过浏览器向服务器发送的内容?服务器是否收到您期望的内容?需要更多细节。您需要缩小问题所在。
-
我尝试使用 {php} 在 tls 文件中插入以下代码 if (Tools::isSubmit('submit_form')){ Db ::getInstance()->Execute("INSERT INTO ps_projectmodule ( 'firstfield', 'secondfield', 'thirdfield') 值 (tools::getValue('firstfield', 'secondfield', 'thirdfield'))"); } {/php} 并且它没有用,我也尝试过我的表单中的操作,它指向一个具有相同代码的 php 文件,例如FILE) 。 '/../../config/config.inc.php';需要一次目录名(文件)。 '/../../init.php'; if (Tools::isSubmit('submit_form')){
-
Db ::getInstance()->Execute("INSERT INTO ps_projectmodule ('firstfield', 'secondfield', 'thirdfield') VALUE (tools::getValue('firstfield', 'secondfield', '第三场'))");并且它也没有工作。当然,浏览器控制台目前有错误,但即使没有任何错误,它也无法正常工作。即使我看到一些错误日志,我也无法理解我所看到的。
-
服务器正确创建了表格,但我不知道如何遵循输入数据的路径
标签: php mysql forms post prestashop