Question

I'm getting a strange error with PDO:{"error":{"text":SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens}}

I tried this sql query and i didn't find,if someone could help me; My code:

$sql = "UPDATE feeds SET status=:statuschosen WHERE idUser=:id AND id:idfeed";
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);  
        $stmt->bindParam("statuschosen", $post->statuschosen);
        $stmt->bindParam("idfeed", $post->idfeed);
        $stmt->bindParam("id", $id);
        $stmt->execute();
        $db = null;
        echo json_encode($post); 
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    }   

My table have this structure:

id  URL idUser  status

Thank you for your help!!!

Was it helpful?

Solution

You were missing an equal sign in your $sql string. Also while binding the params you have used wrong placeholders,See below:

$sql = "UPDATE feeds SET status=:statuschosen WHERE idUser=:id AND id=:idfeed";
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);  
        $stmt->bindParam(":statuschosen", $post->statuschosen);
        $stmt->bindParam(":idfeed", $post->idfeed);
        $stmt->bindParam(":id", $id);
        $stmt->execute();
        $db = null;
        echo json_encode($post); 
    } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    }   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top