POST - Slim PHP

1

I'm a beginner in webservices and I'm studying on top of Slim (PHP) but I'm having a little problem saving something in the database. My job to try to save a new category to the bank is as follows:

function addCategoria(){
    global $app;
    $req = $app->request();
    $paramName = $req->params('name');

    $sql = "INSERT INTO category ('nameCategory') VALUES ($paramName);";
        try {
            $db = getDB();
            $stmt = $db->query($sql); 
            $stmt->bindParam("nameCategory",$paramName);
            $categorias = $stmt->fetchAll(PDO::FETCH_OBJ);
            $db = null;
            echo '{"categorias": ' . json_encode($categorias) . '}';
        } catch(PDOException $e) {
            echo '{"error":{"text":'. $e->getMessage() .'}}';
        }       
}   

I've already tested and I know the category name is coming up in ws but when I run a test I get this:

[   42000 ]

And nothing is saved in the bank. So far I have been able to use the other methods but unfortunately I am having work with the PUT. If anyone can help thank you.

    
asked by anonymous 01.10.2015 / 17:08

1 answer

5

The query is incorrect. The correct structure would be:

$sql = "INSERT INTO category (nameCategory) VALUES ('$paramName');";
    
01.10.2015 / 17:32