Need Help on Post Method


#1

Hi I am facing some issues on Post Method

My code

function signup() {
$request = \Slim\Slim::getInstance()->request();
$update = json_decode($request->getBody()); 
$sql = "INSERT INTO updates (title,link) VALUES (:title, :link)";
try {

$db = getDB();
$stmt = $db->prepare($sql); 
$stmt->bindParam("title", $update->title);
$stmt->bindParam("link", $update->link);
$time=time();
$stmt->execute();
$update->id = $db->lastInsertId();
$db = null;
echo json_encode($update);
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}

it saved as null on database and json result Null (Using Postman) Status getting 200


#2

Why are you using a function where inside try get an instance of Slim and handle the useCase?

Anyway, i have never seen the getInstance() method on Slim 3. Are you using Slim2?

Can you try to see what’s inside the $request and $update variables?