I have the following problem: I am receiving a GET variable in a url. If the variable GET arrives, I send the contents of the variable to my controller.
My controller first brings the whole "sales" table, then I look for the record that has the same content of the GET variable in a column. Finally, I update the status of that record I found.
But nothing happens, and I do not know what I'm doing wrong.
I leave the code:
PHP file where the variable GET is received:
if(isset( $_GET['number'])){
$number = $_GET['number'];
$response = CartController::ctrShowSales($number);
echo $response;
}
PHP Controller:
static public function ctrShowSales($number){
$table = "sales";
$respuesta = CartModel::mdlShowSales($table);
$find = 0;
foreach ($response as $key => $value) {
if ($value["number"] == $number) {
$find = 1;
$id = $value["id"];
break;
}
}
if ($find == 1){
$response2 = CartModel ::mdlUpdateRecord($table, $id);
return $response2;
} else { return "Did not find";}
}
PHP Model:
static public function mdlShowSales($table){
$stmt = Conection::conect()->prepare("SELECT * FROM $table");
$stmt -> execute();
return $stmt -> fetch();
$stmt -> close();
$tmt =null;
}
static public function mdlUpdateRecord($table, $id) {
$stmt = Conection::conect()->prepare("UPDATE $table SET status = :status WHERE $id = :$id");
$stmt->bindParam(":id", $id, PDO::PARAM_INT);
$stmt->bindParam(":status", "Verified", PDO::PARAM_STR);
if($stmt -> execute()){
return "ok";
}else{
return "error";
}
$stmt -> close();
$stmt = null;
}