1 回答
TA贡献1802条经验 获得超4个赞
我修复了它并向其添加了 Mysqli 函数。
谢谢你的所有建议。
<?php
include 'baza.php';
if(isset($_POST['commentSubmit'])) { // Če kliknemo na gumb zažene kodo
$uid = $_POST['uid'];
$date = $_POST['date'];
$message = $_POST['message'];
$sql = "INSERT INTO komentarji (uime, sporocilo, datum) VALUES (?, ?, ?);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../loseFat.php?error=sqlerror"); // Če stavek ne dela
exit();
}
else {
mysqli_stmt_bind_param($stmt, "sss", $uid, $message, $date);
mysqli_stmt_execute($stmt); // Executa stavek v DB
header("Location: ../loseFat.php?comment=success");
exit();
}
}
function getComments($conn) {
$sql = "SELECT * FROM komentarji";
$result = mysqli_query($conn, $sql); // IZVEDE v BAZI
while ($row = mysqli_fetch_assoc($result)) { // da v tabelo in jo shrani v $row
echo "<div class='row'>";
echo "<div class='comment-box'>";
echo $row['uime']."<br>";
echo $row['datum']."<br>";
echo nl2br($row['sporocilo']);
echo "</div>";
echo "</div>";
}
}
?>
- 1 回答
- 0 关注
- 106 浏览
添加回答
举报