0

I've been stuck on this for about 3 days now and asked multiple people about this and no one seems to have an answer to me why this is not working. I cannot figure out why they aren't binding because the bindings work on the select statement but not the update. I know for a fact that $sessCheck['userid'] and $sessCheck['hwid'] are being set because I already printed them out to check if they were null or something.

The request inbound from slim

{"userid": "1000","hwid":"TESTING"}

The function

function updateHWID(){
        $request = Slim::getInstance()->request();
        //$bsreq = utf8_encode();
        $sessCheck = json_decode($request->getBody(), true, 9 );

        $db = getConnection();
        $sql = "SELECT userid,hwID FROM accounts WHERE userid = :userid";
        $stuff = $db->prepare($sql);
        $stuff->bindParam("userid", $sessCheck['userid']);
        $stuff->execute();
        $db = null;

        $rows = $stuff->fetch(PDO::FETCH_ASSOC);


        if ($rows['hwID'] != $sessCheck['hwid']) {
                $sql2 = "UPDATE accounts SET hwID=':hwid' WHERE userID = ':userid';";

                try {
                        $db2 = getConnection();
                        $stmt = $db2->prepare($sql2);
                        //these two param's are not binding
                        $stmt->bindParam("userid", $sessCheck['userid']);
                        $stmt->bindParam("hwid", $sessCheck['hwid']);         
                        $stmt->execute();
                        //$rt = $stmt->fetch(PDO::FETCH_ASSOC);
                        //$stmt->debugDumpParams();
                } catch(PDOException $e) {
                        echo '{"error":{"text":'. $e->getMessage() .'}}';
                }       
        }

}

This is the result incoming on the sql log

      1372 Query     UPDATE accounts SET hwID=':hwid' WHERE userID = ':userid'

I've also tried this as well as using the which also didn't work

$stmt->bindParam(":userid", $sessCheck['userid']);
$stmt->bindParam(":hwid", $sessCheck['hwid']);   

Then I tried this too and it didn't work

$stmt = $db2->prepare("UPDATE accounts SET hwID='?' WHERE userID = '?';");
$stmt->bindParam(1, $sessCheck['hwid'], PDO::PARAM_STR);        
$stmt->bindParam(2, $sessCheck['userid'], PDO::PARAM_INT);
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
Alex Bloom
  • 83
  • 1
  • 1
  • 7

1 Answers1

2

Take the binded parameter names out of their single quotes.

so:
$sql2 = "UPDATE accounts SET hwID=:hwid WHERE userID = :userid;";