Skip to content
Snippets Groups Projects
Commit 62511e5a authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

fix sql echo

parent 49437b2a
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ class Like ...@@ -11,7 +11,7 @@ class Like
public function __construct(Post $post) public function __construct(Post $post)
{ {
$userid = Session::getUser()->getID(); $userid = Session::getUser()->getID();
print("User id is $userid"); // print("User id is $userid");
$postid = $post->getID(); $postid = $post->getID();
$this->id = md5($userid . "-".$postid); $this->id = md5($userid . "-".$postid);
$this->conn = Database::getConnection(); $this->conn = Database::getConnection();
...@@ -28,10 +28,10 @@ class Like ...@@ -28,10 +28,10 @@ class Like
$query_insert = "INSERT INTO `likes` (`id`, `user_id`, `post_id`, `like`, `timestamp`) $query_insert = "INSERT INTO `likes` (`id`, `user_id`, `post_id`, `like`, `timestamp`)
VALUES ('$this->id', '$userid', '$postid', 0, now())"; VALUES ('$this->id', '$userid', '$postid', 0, now())";
$result = $this->conn->query($query_insert); $result = $this->conn->query($query_insert);
if($result){ if ($result) {
if(!$this->conn->query($query)){ if (!$this->conn->query($query)) {
throw new Exception("Unable to create like entry"); throw new Exception("Unable to create like entry");
} }
} }
} }
} }
...@@ -39,14 +39,15 @@ class Like ...@@ -39,14 +39,15 @@ class Like
public function toggleLike() public function toggleLike()
{ {
$liked = $this->getLike(); $liked = $this->getLike();
if(boolval($liked) == true){ if (boolval($liked) == true) {
$this->setLike(0); $this->setLike(0);
} else { } else {
$this->setLike(1); $this->setLike(1);
} }
} }
public function isLiked(){ public function isLiked()
{
return boolval($this->getLike()); return boolval($this->getLike());
} }
} }
...@@ -31,7 +31,7 @@ trait SQLGetterSetter ...@@ -31,7 +31,7 @@ trait SQLGetterSetter
} }
try { try {
$sql = "SELECT `$var` FROM `$this->table` WHERE `id` = '$this->id'"; $sql = "SELECT `$var` FROM `$this->table` WHERE `id` = '$this->id'";
print($sql); // print($sql);
$result = $this->conn->query($sql); $result = $this->conn->query($sql);
if ($result and $result->num_rows == 1) { if ($result and $result->num_rows == 1) {
//print("Res: ".$result->fetch_assoc()["$var"]); //print("Res: ".$result->fetch_assoc()["$var"]);
...@@ -79,7 +79,8 @@ trait SQLGetterSetter ...@@ -79,7 +79,8 @@ trait SQLGetterSetter
} }
} }
public function getID(){ public function getID()
{
return $this->id; return $this->id;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment