PHPとmySQLでテーブルを更新したい。すでにmysqlデータベースにある値から選択した数値を加算または減算する必要があります。「player_qty」に追加すると問題なく機能しますが、減算/削除すると機能しません。多くが削除されたというメッセージが表示されますが、データベースを確認すると、値は同じで、削除されていません。
$register_query = "SELECT * FROM players WHERE player_id='$add_player_id' AND event_name = '$event_name'";
$register_check = mysql_query($register_query, $db);
$register_found_users = mysql_num_rows($register_check);
if($_POST['button'] == "Add") {
if($register_found_users>0){
mysql_query("UPDATE players
SET
player_qty = player_qty + $add_player_qty,
player_pickedup = '1',
event_user = '$event_user'
WHERE player_id = '$add_player_id'");
$msg = $add_player_qty.' more ticket(s) added to '.$add_player_id.'.';
} else {
$insertSQL1 = "
INSERT INTO players
(player_id, player_qty, player_adt, player_level, player_pickedup, event_name, event_type, event_end, event_user)
VALUES
('$add_player_id', '$add_player_qty', NULL, NULL, '1', '$event_name', '$event_type', '$event_end', '$event_user')";
mysql_select_db($dbname, $db);
$Result1 = mysql_query($insertSQL1, $db) or die(mysql_error());
$msg = $add_player_id.' added to DB w/ '.$add_player_qty.' ticket(s)';
}
}elseif($_POST['button'] == "Delete") {
if($register_found_users>0){
mysql_query("UPDATE players
SET
player_qty = player_qty - $add_player_qty,
player_pickedup = '1',
event_user = $event_user
WHERE player_id = '$add_player_id'");
$msg = $add_player_qty.' ticket(s) deleted from '.$add_player_id.'.';
} else {
$msg = $add_player_id.' not in database. Please add manually.';
}
} else {
//
}
<!-- FORM TO ADD PLAYER TO DATABASE IF DOESN'T EXIST -->
<form action="" method="post" enctype="multipart/form-data" name="form_add_player" id="form_add_player" style="display:<?php echo $css;?>;">
<label for="add_player_id">PLAYER #: </label>
<input type="text" name="add_player_id" id="add_player_id" value=""/>
<label for="add_player_qty">QUANTITY: </label>
<select name="add_player_qty" id="add_player_qty">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input name="event_end" type="hidden" id="event_end" value="<?php echo $row_get_type['event_end'];?>" />
<input type="submit" name="button" value="Add" class="button">
<input type="submit" name="button" value="Delete" class="button">
</form>