gpt4 book ai didi

php - X-Cart 4.6 向数据库中的新表提交数据时出错

转载 作者:行者123 更新时间:2023-11-29 09:49:09 25 4
gpt4 key购买 nike

您好,当用户到达订单确认页面时,我正在尝试将一些数据保存到数据库中新创建的表中,但我陷入了困境。我知道 AJAX 调用正在与 php 文件进行通信,因为我可以简单地 console.log 响应(输出),并且我从 php 文件中得到了预期的内容(即: echo 'hello') - 所以这里一切都很好。 p>

我还在 init.php 中注册了新的表别名。

以下是文件 order_message.tpl 中的 JS 代码:

var newData = {
"one":"test one",
"two":"test two"
};

$.ajax({ url: '/newDir/newFile.php',
data: {
dataToSend: newData
},
type: 'post',
success: function(output){
console.log(output);
},
error: function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});

以下是文件 root/newDir/newFile.php 中的 PHP 代码:

require '../init.php';
require '../include/func/func.db.php';

if(isset($_POST['dataToSend']) && !empty($_POST['dataToSend'])) {
$ssData = json_decode($_POST['dataToSend']);
myFunc($ssData);
} else {
die( header('Location: ../404.html') );
}

function myFunc($dt){
$toSaveData = array(
'one' => $dt->one,
'two' => $dt->two
);
func_array2insert ('my_new_table', $toSaveData);
}

我可以看到开发工具中正在进行 AJAX 调用,但它输出以下错误:

我没有在代码中的任何地方引用此路径 - 该路径不存在 - https://localhost/site/newDir/index.php ,所以我不确定这里发生了什么。接下来的 3 个错误来自 AJAX 错误方法。并且数据库中没有存储任何数据。

如果我注释掉“require '../init.php';”我没有收到任何错误,但得到了一长串 html 代码。但仍然没有数据保存到数据库中。

任何人都可以看到可能是什么问题吗?

非常感谢。

最佳答案

1) 将 newFile.php 脚本移动到 stock cart.php 脚本所在的同一文件夹中。

2) 将补丁应用到 PHP 文件

--- old.php 2019-03-14 15:19:10.162222071 +0400
+++ new.php 2019-03-14 15:25:41.160826722 +0400
@@ -1,5 +1,11 @@
-require '../init.php';
-require '../include/func/func.db.php';
+require __DIR__.'/top.inc.php';
+
+define('QUICK_START', true);
+define('SKIP_CHECK_REQUIREMENTS.PHP', true);
+define('USE_SIMPLE_SESSION_INTERFACE', true);
+define('USE_SIMPLE_DB_INTERFACE', true);
+
+require __DIR__.'/init.php';

if(isset($_POST['dataToSend']) && !empty($_POST['dataToSend'])) {
$ssData = json_decode($_POST['dataToSend']);

或在此处下载新版本 https://bt.x-cart.com/view.php?id=50556#attachments

3) 更改该行中的 URL

$.ajax({ url: '/newDir/newFile.php',

到新的。使用相对或绝对路径。

关于php - X-Cart 4.6 向数据库中的新表提交数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55143366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com