hi all im in the middle of following a tutorial online for a rating system and im encountering a problem when i click a number of 1/5 to rate a topic the rating is not going into the database can someone check the code to see what going off
sql tables
CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `articles`
--
INSERT INTO `articles` (`id`, `title`) VALUES
(1, 'test article one'),
(2, 'test article two'),
(3, 'test article three');
and the php code to add to tables
<?php
require_once 'app/init.php';
much appreciated ty jan x
if(isset($_GET['article'], $_GET['rating'])) {
$article = (int)$_GET['article'];
$rating = (int)$_GET['rating'];
if(in_array($rating, [1, 2, 3, 4, 5])) {
$exists = $db->query("SELECT id FROM articles WHERE id = {$article}")->num_rows ? true : false;
if($exists) {
$db->query("INSERT INTO articles_ratings (article, rating) VALUES ({$article}, {$rating})");
}
}
header('location: article.php?id=' . $article);
}
?>
CREATE TABLE IF NOT EXISTS `articles_ratings` (
`id` int(11) NOT NULL,
`article` int(11) NOT NULL,
`rating` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;