首页 > 解决方案 > 成功,在任何地方都没有显示任何错误,但任何数据都不会进入我的数据库

问题描述

<?PHP
session_start();
if (isset($_SESSION['loggedin'])) {

    $loggedin = $_SESSION['loggedin'];
} else {

    header('Location: ../login');
}

$user = $_SESSION['ID'];
$kuva = "Space";
$date = gmdate("j\.m\.Y H:i:s ");


include 'config.php';


$query = $connection->query("INSERT INTO rate(userID, kuva, rate) VALUES(?,?,?)");
$query2 = $connection->query("INSERT INTO picture(nimi, userID, rate, kommentti) VALUES (?,?,?,?)");
$query3 = $connection->query("INSERT INTO comment(userID, picture, date, text) VALUES (?,?,?,?)");

$result = $connection->query("SELECT picture, date, text, user.username FROM comment INNER JOIN users WHERE picture = '$picture' LIMIT 3");


if (isset($_POST['submitPic'])) {
    if (isset($_POST['rating'])) {
        $rating = htmlspecialchars($_POST['rating']);
        $comment = htmlspecialchars($_POST['comment']);
        $query = array($user, $picture, $rating);
        $query2 = array($picture, $user, $rating, $comment);
        $success = '<span style="color:green;font-size:32px;">Success</span>';
    } else {
        $error = '<span style="color:red;font-size:32px;">Error</span>';
    }
}

if (isset($_POST['submitPic'])) {
    if (isset($_POST['comment'])) {

    } else {
        $query3 = array($user, $kuva, $date, $comment);
    }
}
$connection->close();
?>

我在评分和评论后获得成功,但任何数据都没有进入我的数据库

我的代码有什么问题?成功,在任何地方都没有显示任何错误,但任何数据都不会进入我的数据库

我的数据库应该没有问题。只是我没有看到错误

编辑:这是我的 HTML

这是我的 HTML

    <!-- Star rating -->
    <center>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <fieldset class="starability-basic"> 
                <input type="radio" id="rate1" name="rating" value="1" />
                <label for="rate1" title="1/10">1 star</label>

                <input type="radio" id="rate2" name="rating" value="2" />
                <label for="rate2" title="2/10">2 stars</label>

                <input type="radio" id="rate3" name="rating" value="3" />
                <label for="rate3" title="3/10">3 stars</label>

                <input type="radio" id="rate4" name="rating" value="4" />
                <label for="rate4" title="4/10">4 stars</label>

                <input type="radio" id="rate5" name="rating" value="5" />
                <label for="rate5" title="5/10">5 stars</label>

                <input type="radio" id="rate6" name="rating" value="6" />
                <label for="rate6" title="6/10">6 stars</label>

                <input type="radio" id="rate7" name="rating" value="7" />
                <label for="rate7" title="7/10">7 stars</label>

                <input type="radio" id="rate8" name="rating" value="8" />
                <label for="rate8" title="8/10">8 stars</label>

                <input type="radio" id="rate9" name="rating" value="9" />
                <label for="rate9" title="9/10">9 stars</label>

                <input type="radio" id="rate10" name="rating" value="10" />
                <label for="rate10" title="10/10">10 stars</label>
            </fieldset>
    </center>

    <center>
        <textarea name="comment" cols="50" rows="4"></textarea>
    </textarea>
</center>
<center>
    <button type="submit" name="submitPic" class="submitPic">Send</button>
</center>
</form>

标签: phphtmlmysql

解决方案


为什么不使用准备好的语句。

$query = $connection->prepare("INSERT INTO rate(userID, kuva, rate) VALUES(?,?,?)");
$query->bind_param('iii', $user, $picture, $rating);
$query->execute();
$query->close();

推荐阅读