$armorLocationMod = 0;
    }
}
if ($mechArmorValues->fetch_object()->{$armorLocation} < $maxArmor) {
    updateArmor($armorLocation, $armorLocationMod, $linked, $altArmorLocation, $mechIdPassed, $conn);
}
if ($revAltArmor) {
    $armorThis = mysqli_query($conn, $queryExternalArmor)->fetch_object()->{$armorLocation};
    if ($revAltArmor + $armorThis > $maxArmor) {
        updateArmor($armorLocation2, -1, $linked, $altArmorLocation2, $mechIdPassed, $conn);
    }
    if ($altArmorLocation2) {
        $revAltArmor = mysqli_query($conn, $queryExternalArmor)->fetch_object()->{$altArmorLocation2};
        $armorThis = mysqli_query($conn, $queryExternalArmor)->fetch_object()->{$altArmorLocation};
        if ($revAltArmor + $armorThis > $maxArmor) {
            updateArmor($altArmorLocation2, -1, $linked, $armorLocation2, $mechIdPassed, $conn);
        }
    }
}
function updateArmor($armorLocation, $armorLocationMod, $linked, $altArmorLocation, $mechIdPassed, $conn)
{
    $retval2 = mysqli_query($conn, "UPDATE mechexternalarmor SET {$armorLocation} = {$armorLocation}+{$armorLocationMod} WHERE mechID = {$mechIdPassed}");
    if (!$retval2) {
        die('Could not update data: ' . mysqli_error($conn));
    }
    echo "Updated data successfully\n";
    if ($linked == 'yes') {
        $queryMirrorArmor = "SELECT * FROM mechexternalarmor WHERE mechID = {$mechIdPassed}";
        $mirrorArmor = mysqli_query($conn, $queryMirrorArmor)->fetch_object()->{$armorLocation};
        $retval4 = mysqli_query($conn, "UPDATE mechexternalarmor SET {$altArmorLocation} = {$mirrorArmor} WHERE mechID = {$mechIdPassed}");
        if (!$retval4) {
示例#2
0
<?php

require_once "functions.php";
if (!isset($_SESSION["logged_in_user_id"])) {
    header("Location: login.php");
}
if (isset($_POST["update_armor"])) {
    updateArmor($_POST["id"], $_POST["armor_type"], $_POST["armor_race"], $_POST["armor_color"]);
}
if (isset($_GET["edit_id"])) {
    echo $_GET["edit_id"];
    $armor = getEditData($_GET["edit_id"]);
} else {
    echo "Viga";
    header("Location: table.php");
}
?>

<h2>Muuda armori soovitust.</h2>
<form action="<?php 
echo htmlspecialchars($_SERVER["PHP_SELF"]);
?>
" method="post" >
	<input type="hidden" name="id" value="<?php 
echo $_GET["edit_id"];
?>
">
	<label for="armor_type">Armori tüüp</label><br>
	<input id="armor_type" name="armor_type" type="text" value="<?php 
echo $armor->type;
?>