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
public function __construct(Post $post)
{
$userid = Session::getUser()->getID();
print("User id is $userid");
// print("User id is $userid");
$postid = $post->getID();
$this->id = md5($userid . "-".$postid);
$this->conn = Database::getConnection();
......@@ -28,10 +28,10 @@ class Like
$query_insert = "INSERT INTO `likes` (`id`, `user_id`, `post_id`, `like`, `timestamp`)
VALUES ('$this->id', '$userid', '$postid', 0, now())";
$result = $this->conn->query($query_insert);
if($result){
if(!$this->conn->query($query)){
if ($result) {
if (!$this->conn->query($query)) {
throw new Exception("Unable to create like entry");
}
}
}
}
}
......@@ -39,14 +39,15 @@ class Like
public function toggleLike()
{
$liked = $this->getLike();
if(boolval($liked) == true){
if (boolval($liked) == true) {
$this->setLike(0);
} else {
$this->setLike(1);
}
}
public function isLiked(){
public function isLiked()
{
return boolval($this->getLike());
}
}
......@@ -31,7 +31,7 @@ trait SQLGetterSetter
}
try {
$sql = "SELECT `$var` FROM `$this->table` WHERE `id` = '$this->id'";
print($sql);
// print($sql);
$result = $this->conn->query($sql);
if ($result and $result->num_rows == 1) {
//print("Res: ".$result->fetch_assoc()["$var"]);
......@@ -79,7 +79,8 @@ trait SQLGetterSetter
}
}
public function getID(){
public function getID()
{
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