0

im sending id of the row as scanID, setting table name, item, value in PHP and calling out the model to update the specific row, the query is working perfectly but the row is not updating.

trying to change status from 0 to 1 as item = column and value = 1.

PHP Code

if(isset($_POST["scanID"])){

$table = 'scan-start';
$item1 = 'scanStatus';
$value1= 1;
$value=$_POST["scanID"];
$answer = CalloutModel::mdlUpdateScanStatus($table, $item1, $value1, $value);
}

Model

static public function mdlUpdateScanStatus($table, $item1, $value1, $value){

    $stmt = Connection::connect()->prepare("UPDATE `$table` SET $item1 = :$item1 WHERE id = :id");

    $stmt -> bindParam(":".$item1,$value1, PDO::PARAM_STR);
    $stmt -> bindParam(":id",$value, PDO::PARAM_STR);

    if($stmt -> execute()){

        return $stmt->rowCount();
    
    }else{

        return "error"; 

    }

    $stmt -> close();

    $stmt = null;
}

rowCount() is returning 0.. I know I'm missing something small, tried changing value to string but no luck, any help would be greatly appreciated.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
jinx
  • 5
  • 5
  • Either you are updating to the same value or didn't enable [error reporting](https://stackoverflow.com/questions/32648371/why-does-this-pdo-statement-silently-fail) – Your Common Sense Mar 13 '22 at 06:37
  • Also, mdlUpdateScanStatus($table, $item1, $value1, $value) is both DANGEROUS and unnecessarily elaborate. WHY don't you write the table name and the column name RIGHT IN THE QUERY? It's the Update Scan Status procedure, WHAT ELSE it can possibly update? – Your Common Sense Mar 13 '22 at 06:40
  • value is 0 and im trying to update it to 1.. and I also enabled error reporting but still same issue. – jinx Mar 13 '22 at 06:41
  • Then you have to verify everything once more. when you are changing 0 to 1 and there is no error then rowCount will be 1 – Your Common Sense Mar 13 '22 at 07:19

0 Answers0