Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Decrementing a column - code not working

Decrementing a column - code not working

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databaseannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dwayner79
    wrote on last edited by
    #1

    I was told this would work, but it is not. I do not know the value in a particular column, but I want to decrease it by a number. In other words, Dude buys 2 widgets, the inventory of said widget gets reduced by two.

    $u_sql='UPDATE sale_inventory SET invqty = invqty - '.$boughtqty.' WHERE invProdID='.$row['ProdID'];

    This yields an SQL Statement like:

    UPDATE sale_inventory SET invqty = invqty - 1 WHERE invProdID=1234567

    I cannot tell why this is not working. Thanks in advance.

    ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW

    G C 2 Replies Last reply
    0
    • D Dwayner79

      I was told this would work, but it is not. I do not know the value in a particular column, but I want to decrease it by a number. In other words, Dude buys 2 widgets, the inventory of said widget gets reduced by two.

      $u_sql='UPDATE sale_inventory SET invqty = invqty - '.$boughtqty.' WHERE invProdID='.$row['ProdID'];

      This yields an SQL Statement like:

      UPDATE sale_inventory SET invqty = invqty - 1 WHERE invProdID=1234567

      I cannot tell why this is not working. Thanks in advance.

      ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      The SQL looks fine. Could you show the PHP code that executes the SQL?

      1 Reply Last reply
      0
      • D Dwayner79

        I was told this would work, but it is not. I do not know the value in a particular column, but I want to decrease it by a number. In other words, Dude buys 2 widgets, the inventory of said widget gets reduced by two.

        $u_sql='UPDATE sale_inventory SET invqty = invqty - '.$boughtqty.' WHERE invProdID='.$row['ProdID'];

        This yields an SQL Statement like:

        UPDATE sale_inventory SET invqty = invqty - 1 WHERE invProdID=1234567

        I cannot tell why this is not working. Thanks in advance.

        ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW

        C Offline
        C Offline
        cjoki
        wrote on last edited by
        #3

        do you have an error message, can you use something like.. $rst = mysql_query($u_sql) or die(mysql_error()); this will print the message coming from the mysql db.

        Chris J www.redash.org

        D 1 Reply Last reply
        0
        • C cjoki

          do you have an error message, can you use something like.. $rst = mysql_query($u_sql) or die(mysql_error()); this will print the message coming from the mysql db.

          Chris J www.redash.org

          D Offline
          D Offline
          Dwayner79
          wrote on last edited by
          #4

          Thanks for the replys... I have error checking

          $u_result = @mysql_query($u_sql, $link_b);
          if (!$u_result) { exit('

          Error reducing inventory: ' . mysql_error() . '

          ');}

          There is no error thrown, just that value is not reduced. Like an idiot, when scrubbing my data, I probably should have left it... My invProdID has - marks in them, so I needed quotes around them. Total newb error. Thank you both anyway. You assurances that it seemed right made me think down the typo path.

          ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups