【问题标题】:ajax won't connect with mysqli?ajax 无法连接mysqli?
【发布时间】:2015-06-02 19:42:32
【问题描述】:

我正在尝试通过 ajax 调用与 myqli 连接。 因为我正在测试用户的数据库输入。

脚本在以下位置崩溃: $testBase = new mysqli("sfd", "sdf", "sdg", "sdf");

在控制台中显示: Uncaught SyntaxError: Unexpected token

是的,你搜索了这个问题,但是大多数人在你进行查询时会遇到该错误,而当我尝试创建 mysqli 连接时,我的已经这样做了。

Ajax 脚本:

if (error == false){
var name = $('#name').val(),
    url = $('#url').val(),
    datahost = $('#datahost').val(),
    datausername = $('#datausername').val(),
    datapassword = $('#datapassword').val(),
    dataname = $('#dataname').val(),
    license = $('#license').val(),
    data = 'name='+ name +'&url='+ url +'&datahost='+ datahost +'&datausername='+ datausername +'&datapassword='+ datapassword +'&dataname='+ dataname +'&license='+ license;

$( "#trans" ).fadeIn( 500, function() {
    $.ajax({
        type: "POST",
        url: "handlers/install.php",
        data: data,
        success: function(e){ // this happen after we get result
            react(e);
        }
    });
});

}

请帮帮我

handelers/install.php 的响应是:

"<br />\n<b>Warning</b>:  mysqli::mysqli(): (HY000/1130): Host 'server2.ughost.nl' is not allowed to connect to this MySQL server in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>59</b><br />\n<br />\n<b>Warning</b>:  mysqli::close(): Couldn't fetch mysqli in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>75</b><br />\n{\"ban\":0,\"error\":0,\"license\":0,\"url\":0,\"name\":0,\"sql\":0,\"message\":\"localhost + asd + asdas+dasf\"}"

【问题讨论】:

  • 你的ajax代码在哪里?? js代码相关的错误
  • 我把它放在问题里
  • 请贴出出现此错误的php代码
  • 连接有效吗?
  • 不,它无效。我正在尝试检查它是否有效

标签: php jquery mysql ajax mysqli


【解决方案1】:

好的,问题是当登录不正确时 install.php 总是给出警告。 但我需要检查它,因为这是用户输入,所以我是如何修复它的?

error_reporting(0);
                        $testBase = new mysqli($datahost, $datausername, $datapassword, $dataname);
                        error_reporting(1);
                        if ($testBase->connect_errno) {
                            $response['sql'] = 1;
                            $testBase->close();
                        } else {
                            //can connect with database
                            $testBase->close();

                        }

【讨论】:

  • 不要将问题更新作为答案发布,而是更新您的实际问题
  • 但是您在答案中提出了一个新问题
  • 不,我说我是怎么解决的?我给出了答案
猜你喜欢
  • 2022-01-05
  • 2016-05-23
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 2017-12-06
  • 2018-01-11
  • 2015-11-20
  • 2013-07-13
相关资源
最近更新 更多