Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7917731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:14:59+00:00 2026-06-03T15:14:59+00:00

I want to update a table with PHP and mySQL. I need to add

  • 0

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.

$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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:15:02+00:00Added an answer on June 3, 2026 at 3:15 pm

    In your substraction query you are not setting the ' on one of your entry values – maybe this is causing an mysql error and thus the query does not get executed.

    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'");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

work environment: php + mysql I want to add an entity from DAO layer
I'm building a table from which I want to update different fields of a
I want to ascend MYSQL from a value in the database. Hypothetically: database with
looking for help with mysql/php I'm using query to update table if user plays
I want to update a table to indicate that some rows are parents of
I want to update a column in a table making a join on other
I want to Update Column of a Table where ColumnName will be DropDown.SelectedValue. Example:
I have a Table View Controller with cells. I want to update the text
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
I have two tables nol_art and #tmpIzm I want to update nol_art with value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.