added like to comments etc

This commit is contained in:
nooahe committed 2022-11-15 14:59:24 +01:00
1 parent f365ca3592
commit 3d178fd58e
5 files changed
+357 -41

No files matched your search

+24 -2
View File
@@ -7,17 +7,39 @@ require_once('data.php');
$db = dbVerbindungErzeugen();
$id = $_GET["id"];
$sql = "SELECT likes FROM idee WHERE id = $id";
$typ = $_GET["typ"];
if ($typ == "idee") {
$sql = "SELECT likes FROM idee WHERE id = $id";
$resultat = $db->query($sql);
$likeCount = $resultat ->fetchColumn();
$likeCount += 1;
echo ($likeCount);
$sql = "UPDATE idee SET likes=? WHERE id=?";
$stmt = $db->prepare($sql);
$stmt->execute(array($likeCount, $id));
} elseif ($typ == "kommentar"){
$sql = "SELECT k_likes FROM kommentar WHERE k_id = $id";
$resultat = $db->query($sql);
$likeCount = $resultat ->fetchColumn();
$likeCount += 1;
$sql = "UPDATE kommentar SET k_likes=? WHERE k_id=?";
$stmt = $db->prepare($sql);
$stmt->execute(array($likeCount, $id));
}
echo ($likeCount);
?>
+1 -1
View File
@@ -23,7 +23,7 @@ $stmt->execute(array($titel, $inhalt, $lat, $lng));
echo $db->lastInsertId();
header("Location: https://751068-4.web.fhgr.ch/");
header("Location: /");
die();
?>
+46
View File
@@ -0,0 +1,46 @@
<?php
require_once('data.php');
?>
<?php
$db = dbVerbindungErzeugen();
$id = $_GET["id"];
$typ = $_GET["typ"];
if ($typ == "idee") {
$sql = "SELECT likes FROM idee WHERE id = $id";
$resultat = $db->query($sql);
$likeCount = $resultat ->fetchColumn();
if ($likeCount > 0){
$likeCount -= 1;
}
echo ($likeCount);
$sql = "UPDATE idee SET likes=? WHERE id=?";
$stmt = $db->prepare($sql);
$stmt->execute(array($likeCount, $id));
} elseif ($typ == "kommentar"){
$sql = "SELECT k_likes FROM kommentar WHERE k_id = $id";
$resultat = $db->query($sql);
$likeCount = $resultat ->fetchColumn();
$likeCount -= 1;
echo ($likeCount);
$sql = "UPDATE kommentar SET k_likes=? WHERE k_id=?";
$stmt = $db->prepare($sql);
$stmt->execute(array($likeCount, $id));
}
?>