dongluobei9359 2014-05-07 18:35
浏览 37
已采纳

SQL查询似乎不起作用

I am making a PHP script at the moment and I am making an install page to go with it. Before running the install script the user has to edit the config file and enter their database credentials (they have to create the database first).

The install script starts by checking they have met the requirements. If they have then display the "Import Tables" button. This is where I am having problems. Here is my code:

<?php 

if (isset($_POST['step2'])) {
    if (isset($success_php, $success_mysqli, $step_1_complete)) {
        // Import SQL tables

        $sql = ("
            CREATE TABLE `banned_ips` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `ip` varchar(15) NOT NULL,
            `reason` text NOT NULL,
            PRIMARY KEY (`id`),
            UNIQUE KEY `ip` (`ip`)
            ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;
            ");

        if ($db->execute($sql)) {
            $success_import = true;
            $step_2_complete = true;
        }

        $db->close();
    }
}

}

?>

I was thinking of loading it straight from the .sql file however I am trying to make the script as compatible as I can across different servers, so therefore, I chose to do the query like so.

What I am asking is whether there is an issue with my above query and if so, how can I resolve it. At the moment when I click the button to test it, the table and its columns are not created.

  • 写回答

1条回答 默认 最新

  • doudou6050 2014-05-07 18:54
    关注

    (To close the question and marked as solved)

    Your table creation code checks out. As I said in my commment(s) your code is dependant in regards to the conditional statements you've set.

    If you're using this with a form (which seems obvious), check that your variables are properly set/named.

    I am questioning this also isset($success_php, $success_mysqli, $step_1_complete) so double-check everything.

    "@Fred-ii- Thanks, the error was because two of the variables weren't set before it tried to execute."

    Add error reporting to the top of your file(s) when in production.

    error_reporting(E_ALL);
    ini_set('display_errors', 1); 
    

    Plus, I quote John Conde:

    "You don't need a unique key if the column is the primary key. They're already unique."

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?