//Set content-type and charset for page header("Content-Type: text/html; charset=utf-8"); //Get article title $index = $_GET["article"]; //Remove the .xml extension if it exists, so that old links still work if (preg_match('/(\.xml$)/', $index)) { $index = substr($index, 0, strlen($index) - 4); } //Connect to article database $servername = "localhost"; $username = "ShovelDuckAdmin"; $password = ".Sdaen24@@@sSs"; $dbname = "ShovelDuck"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //Change character set to utf8 if (!$conn->set_charset("utf8")) { die("Error loading character set utf8: " . $mysqli->error); } //Get article entry $sql = "SELECT * FROM Articles WHERE url = '" . $index . "' LIMIT 1"; $article = $conn->query($sql)->fetch_assoc(); //Get video, if exists $sql = "SELECT * FROM Articles WHERE relatedUrl = '" . $index . "' AND date < '" . date("Y-m-d H:i:s", time()-25200) . "' LIMIT 1"; $result = $conn->query($sql); if (mysqli_num_rows($result) == 0) { $video = null; } else { $video = $result->fetch_assoc(); } //Get 3 latest articles, exclude the current article and current category $sql = "SELECT * FROM Articles WHERE url <> '" . $index . "' AND category <> '" . $article["category"] . "' AND medium = 'article' AND date < '" . date("Y-m-d H:i:s", time()-25200) . "' ORDER BY date DESC LIMIT 3"; $latestAll = $conn->query($sql); //Get 3 latest articles of the same category, excluding the current article $sql = "SELECT * FROM Articles WHERE url <> '" . $index . "' AND medium = 'article' AND category = '" . $article["category"] . "' AND date < '" . date("Y-m-d H:i:s", time()-25200) . "' ORDER BY date DESC LIMIT 3"; $latestCategory = $conn->query($sql); //Get email and add to database if ($_SERVER["REQUEST_METHOD"] == "POST") { $email = $_POST["email"]; //Test for valid format again if (preg_match('/(^.+@.+\..+$)/', $email) != 1) { $subscribed = "error"; } else { $sql = "SELECT COUNT(*) AS total FROM MailingList WHERE email = '" . $email . "'"; $email_count = $conn->query($sql)->fetch_assoc()["total"]; if ($email_count != 0) { $subscribed = "already"; } else { $sql = "INSERT INTO MailingList VALUES ('" . $email . "')"; if ($conn->query($sql) === TRUE) { $subscribed = "true"; } else { $subscribed = "error"; } } } } else { //Update visit counter for article $sql = "UPDATE Articles SET visits = visits + 1 WHERE url = '" . $index . "'"; $conn->query($sql); //Update visit counter for video $sql = "UPDATE Articles SET visits = visits + 1 WHERE relatedUrl = '" . $index . "' AND date < '" . date("Y-m-d H:i:s", time()-25200) ."'"; $conn->query($sql); } ?> - ShovelDuck


| January 1st, 1970 12:00 AM


Subscribe to our weekly newsletter

E-mail:

Recent News