prestashop 1.6:如何在ajax.php中编写插入查询

时间:2017-06-03 06:42:50

标签: prestashop-1.6

我只是在插入查询中使用prestashop。我已经附加了我的ajax文件。我已经包含了所有支持的文件但是数据没有插入到这个表中。我不知道什么是错误?。检查并且帮我。

include '../../config/settings.inc.php';
include '../../config/defines.inc.php';
include '../../config/config.inc.php';

    $api=$_REQUEST['api_key'];
    $install=$_REQUEST['installtion_id'];
    $percentages=$_REQUEST['dep_per'];
    $package=$_REQUEST['dep_plan'];


       $res = Db::getInstance()->insert('pay4later_setting',array(
        'api_key'       => '$api', 
        'installtion_id'      => '$install',
        'deposite_percentage' =>'$percentages',
         'package_plan' =>'$package',
    ));

1 个答案:

答案 0 :(得分:0)

你在哪里保留了你的ajax请求。哦,没问题。

例如,

在prestashop中,我通过configure.tpl文件发送了我的ajax请求

<强> configure.tpl

<head>
<script>
$(document).ready(function(){

        $('#submit_label').click(function(){
               var data = "welcome";
                $.ajax({
                type:"POST",
                dataType:"JSON",
                url:baseDir+'modules/anything/data.php',
                data:{
                ajax:true,
                name:data,
                },
                success: function(html){

                    if(html.added)
                    {
                         $("#success").html(html.added);

                    }


            } 
                });

        });

});

这里我使用data.php作为php文件

<强> data.php

<?php
require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');

if(isset($_POST['name']))
{
    $label_name = $_POST['name']; or you can use Tools::getValue("name");

    $connect_db = Db::getInstance()->insert('label', array(
    'label_name' => pSQL($label_name),
    ));

    $getin['added'] = 'Label created successfully';//here we have using JSON datatype so we need to create object and store some values.

    echo json_encode($getin);


}

谢谢&amp;问候, 克里希纳。