Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a Edit_Post.php page to enable a user edit posts already made. #57

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Api/create_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
if(DB::create_post($conn,$id,$post,$topic)==TRUE){

$data=[
'res'=>'Post Successful',
'res'=>'Post Created Successful',
'status'=>200
];

Expand Down
84 changes: 84 additions & 0 deletions Api/edit_post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
require_once('../autoloader.php');
use Helper\Database as DB;
use Helper\Jwt_client as jwt;


if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['token']) && !empty($_POST['token'])){

$arr=jwt::decode($_POST['token']);

$conn=DB::db_connect();
if(DB::confirm_id($conn,$arr['data']->id)){
if(isset($_POST["post"]) && !empty($_POST["post"]) && isset($_POST["topic"]) && !empty($_POST["topic"]) ){

$post=$_POST["post"];
$topic=$_POST["topic"];
$id=$arr['data']->id;
if(!(DB::user_blocked($conn,$id))){
if(DB::edit_post($conn,$id,$post,$topic)==TRUE){
$data=[
'res'=>'Post Updated Successfully',
'status'=>200
];


echo json_encode($data);
}else{
$data=[
'res'=>'Update failed',
'status'=>404,
'err'=>mysqli_error($conn)
];


echo json_encode($data);
}
}else{
$data=[
'res'=>'Your account is currently blocked',
'status'=>200,
'err'=>mysqli_error($conn)
];


echo json_encode($data);
}
}else{
$data=[
'res'=>'Invalid Credentials',
'status'=>404
];


echo json_encode($data);
}
}else{
$data=[
'res'=>'Invalid User',
'status'=>404
];

//http_response_code(404);
echo json_encode($data);
}
}else{
$data=[
'res'=>'No token was sent',
'status'=>404
];

//http_response_code(404);
echo json_encode($data);
}
}else{
$data=[
'res'=>'Invalid Request Method',
'status'=>404
];
//http_response_code(404);
echo json_encode($data);
}

?>
9 changes: 9 additions & 0 deletions Helpers/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ public static function create_post($conn,$user_id,$content,$topic){
}
}

//EDIT POST
public static function edit_post($conn,$id,$post,$topic){
$sql = "UPDATE users SET post_topic = $topic, post = $post WHERE post_id = $id";
$result = mysqli_query($conn,$sql);
if($result == TRUE){
return TRUE;
}
}

// Confirming a user
public static function confirm_id($conn,$id){

Expand Down