php - 成功,在任何地方都没有显示任何错误,但任何数据都不会进入我的数据库
问题描述
<?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>
解决方案
为什么不使用准备好的语句。
$query = $connection->prepare("INSERT INTO rate(userID, kuva, rate) VALUES(?,?,?)");
$query->bind_param('iii', $user, $picture, $rating);
$query->execute();
$query->close();
推荐阅读
- javascript - 如何将组件作为道具传递给Vue.js中的另一个组件
- amazon-web-services - 错误:意外的服务器响应:尝试通过 Amazon API 网关 Websocket API 连接到 lambda 函数时出现 502
- c++ - 阵列衰减和修改
- fastapi - `validator` 方法是否需要检查所需的参数?
- scheme - 我们如何在使用 `call/cc` 的程序和使用 CPS 编写的函数的程序之间进行转换?
- java - 解析数字字符串时的额外空字符串
- python - Selenium 无法在我的 Facebook 页面上的“发帖”窗口上写字
- dataframe - 模式需要的字段少于声明的字段
- c# - WPF ReactiveUI ListBox 使用绑定的 ItemsSource 填充,但 ComboBox 没有
- amp-html - 用户点击返回按钮后 AMP 重置所选选项