Increment my variable in a database with UPDATE in PHP

后端 未结 2 2047
花落未央
花落未央 2021-01-29 06:24

I get the variable \'stock\' from my database. I would like increment my variable with an update with this code:

$stock = $_POST[\'stock\']

$nom = \'salade\';
$         


        
相关标签:
2条回答
  • 2021-01-29 06:35

    Considering that you're saying all you need to is increment by 1 each row WHERE nom = :nom (I guess your actual code isn't wrong with $ instead of : or it wouldn't even "increment by 8" as you said you're already achieving... remember do edit this on your question, please):

    UPDATE
        ingredients
    SET
        stock=stock+1
    WHERE
        nom = :nom;
    

    Jusk pick what you already had and add 1 stock=stock+1.

    0 讨论(0)
  • 2021-01-29 06:44

    You can use like this for variable in text query.

    $req= ("UPDATE ingredients SET stock='".($stock+1)."' WHERE nom = :nom;");
    
    0 讨论(0)
提交回复
热议问题