PHP MySQLi准备好的声明不起作用

时间:2014-05-30 23:39:46

标签: php mysql mysqli

  

编辑开始

所以我发现我的代码存在问题。这是以下一行

if(isset($_REQUEST['faq_submit'])) {

我不确定这条线路有什么问题?为什么它不能正常工作?

  

编辑结束

出于某种原因,我准备的陈述不起作用。它似乎也没有在错误日志中显示任何错误。现在我可能只是在那里做错了但是我相信这里有人可以发现我做错了什么哈哈...我尝试用几种不同的方式修复它而且只是不成功所以在这里寻求帮助总是一个很好的度假胜地! / p>

这是我添加问题的PHP代码

// Required Configuration
include_once('required.php');

// double check page was accessed via submit button
if(isset($_REQUEST['faq_submit'])) {
    // get data that sent from form
    $topic=trim($_REQUEST['faq_topic']);
    $detail=trim($_REQUEST['faq_detail']);
    $name=trim($_REQUEST['faq_name']);
    $email=trim($_REQUEST['faq_email']);

    // check if all forms are filled out
    if(!empty($topic) && !empty($detail) && !empty($name) && !empty($email)) {
        // Validate Email
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
            // Prepared Insert Statement
            $stmt = $mysqli->prepare('INSERT INTO forum_question (`topic`, `detail`, `name`, `email`, `datetime`) VALUES (?, ?, ?, ?, ?)');

            // Bind Variables To Values
            $stmt->bind_param('sssss', $topic, $detail, $name, $email, $datetime);

            // Execute Prepared Statement
            $stmt->execute();

            // Print Results
            $html = '<div class="alert alert-dismissable alert-success"><button type="button" class="close" data-dismiss="alert">×</button>You <strong>successfully</strong> submited a question to the FAQ bored.</div>';
            print($html);

            // Close Connections and Statement
            $stmt->close(); // Statement
            $mysqli->close(); // MySQLi
        } else {
            // Email Validation Failed
            $html = '<div class="alert alert-dismissable alert-danger"><button type="button" class="close" data-dismiss="alert">×</button>Your <strong>email</strong> was invalid.</div>';
            print($html);
        }
    } else {
        // If the required items were not filled out print the following
        $html = '<div class="alert alert-dismissable alert-danger"><button type="button" class="close" data-dismiss="alert">×</button><strong>All</strong> forms are required.</div>';
        print($html);
    }
}

这是required.php文件,虽然我已经删除了一些登录信息。

$datetime=date("m/d/y h:i"); // Format Date And Time

// Connect
$mysqli = new mysqli('host', 'user', 'pass', 'db');

// Check Connection
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

1 个答案:

答案 0 :(得分:2)

您是否尝试检查是否有任何语句错误被抛出? http://www.php.net/manual/en/mysqli-stmt.error.php