I have an error in my test code. I want to subtract the current stocks I have as raw materials with the new ones and update them in the database, but it does not update any value. My insert entry is successful, update is not done at all, only my metal / iron is completely set to 0.
I have included extra var_dump commands, up to my insert command the values are correct, after that as I said only metal / iron updates to 0. Although I have 5000 villageMetal and enter iron 500.
So 5000 - 500. the value comes to 0
public function sellingMaterials(int $villageId,int $iron,int $wood,int $stone,int $cereals,int $silver){
$error = false;
$objectsInt = [
$iron,
$wood,
$stone,
$cereals,
$silver
];
foreach($objectsInt as $objInt){
if($objInt <= 0){
$error = true;
return "Darf nicht 0 oder eine negative Zahl sein.";
}
}
foreach($objectsInt as $raw){
if(!is_numeric($raw)){
$error = true;
return "Die Zahlen sind keine Nummer";
}
}
$stmt = $this->pdo->prepare("SELECT * FROM village WHERE villageId = ?");
$stmt->execute([$villageId]);
$result = $stmt->fetch();
if($result["villageMetal"] < $iron){
$error = true;
}
if($result["villageWood"] < $wood){
$error = true;
}
if($result["villageStone"] < $stone){
$error = true;
}
if($result["villageCereals"] < $cereals){
$error = true;
}
$completeRaw = $iron+$wood+$stone+$cereals;
//Ausgabe wieviele Händler existieren
$sellingDealers = $this->getMarketDealers($villageId);
$ak = time();
$marketInsertEnd = $ak + 86400;
if($error != true){
$akIronStock = $result["villageMetal"] - $iron;
$akWoodStock = $result["villageWood"] - $wood;
$akStoneStock = $result["villageStone"] - $stone;
$akCerealsStock = $result["villageCereals"] - $cereals;
var_dump($akIronStock);
$stmt = $this->pdo->prepare("UPDATE village SET villageMetal = ? AND villageWood = ? AND villageStone = ? AND villageCereals = ? WHERE villageID = ?");
$stmt->execute([$akIronStock, $akWoodStock, $akStoneStock, $akCerealsStock, $villageId]);
$stmt = $this->pdo->prepare("INSERT INTO marketplace_insert (villageID, iron, wood, stone, cereals, silver, marketInsertEnd) VALUES (?,?,?,?,?,?,?)");
$stmt->execute([$villageId, $iron, $wood, $stone, $cereals, $silver, $marketInsertEnd]);
}
}