PHP MySQLi准备的语句不起作用

kevingilbert100

编辑开始

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

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

我不确定这条线怎么了?为什么它不能正常工作?

编辑结束

由于某种原因,我准备的语句不起作用。同样,它似乎在错误日志中未显示任何错误。现在我可能只是在那儿做错了什么,但我确信这里有人会发现我做过的错误……哈哈...我尝试用几种不同的方式修复它,但是没有成功,因此在这里寻求帮助永远是一个好方法!

这是我的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();
}
哲学

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章