how to update mysql with php when subtracting

Whawgallearia

New Member
I want to update a table with PHP and mySQL.I need to add or subtract whatever number I select from a value already in a mysql db.It works ok when I add to "player_qty" but not when I subtract/delete. It gives me the message I want, that so many have been deleted but when I check the database, teh value is the same -- not deleting.\[code\]$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="http://stackoverflow.com/questions/10536929/1">1</option> <option value="http://stackoverflow.com/questions/10536929/2" selected>2</option> <option value="http://stackoverflow.com/questions/10536929/3">3</option> <option value="http://stackoverflow.com/questions/10536929/4">4</option> <option value="http://stackoverflow.com/questions/10536929/5">5</option> <option value="http://stackoverflow.com/questions/10536929/6">6</option> <option value="http://stackoverflow.com/questions/10536929/7">7</option> <option value="http://stackoverflow.com/questions/10536929/8">8</option> <option value="http://stackoverflow.com/questions/10536929/9">9</option> <option value="http://stackoverflow.com/questions/10536929/10">10</option> </select> <input name="event_end" type="hidden" id="event_end" value="http://stackoverflow.com/questions/10536929/<?php echo $row_get_type['event_end'];?>" /> <input type="submit" name="button" value="http://stackoverflow.com/questions/10536929/Add" class="button"> <input type="submit" name="button" value="http://stackoverflow.com/questions/10536929/Delete" class="button"> </form>\[/code\]
 
Back
Top