我需要在我的数据库中插入评级,所以我尝试使用此链接集:
<?php foreach (range(1, 5) as $ocena) { ?>
<a href="ocena.php?clanak=<?php echo $clanci['id'];?>&ocena=<?php echo $ocena; ?>"><?php echo $ocena; ?></a>
<?php } ?>
And in my ocena.php i have $_get method to retrive values and store it in database:
<?php
include_once 'includes/konekcija.php';
if (isset($_GET['clanak'], $_GET['ocena'])) {
$clanak = $_GET['clanak'];
$ocena = $_GET['ocena'];
if (in_array($ocena, [1,2,3,4,5])) {
$niz = $pdo->prepare("SELECT id FROM clanci WHERE id =:id");
$niz->bindParam(":id", $clanak);
$niz->execute();
$red = $niz->fetch();
if ($red) {
$upit = $pdo->prepare("INSERT INTO ocene (clanak, ocena) VALUES (?, ?)");
$upit->bindValue(1, $clanak);
$upit->bindValue(2, $ocene);
$upit->execute();
header('Location: clanak.php?id=' .$clanak);
} else {
echo 'Nesto nije u redu.';
}
}
}
所以它重新定位,一切似乎都很好,但当我检查我的数据库时,结果现在已插入。我没看到什么?