why my addition in php always update 2 in column at my database2019 Community Moderator ElectionHow to secure database passwords in PHP?How do I see what character set a MySQL database / table / column is?MySQL query optimization - increase speed and efficiencyWhy shouldn't I use mysql_* functions in PHP?Cannot create new tables on the fly with EloquentGetting data from mysql query based on Date durationNeed help in SQL query performanceLaravel 5.3 eager loaded relations using method with()What is better in performance for 1-to-1 relationship: a new table or a VARCHAR column with a lot of empty entriesvoyager databases and MariaDB server

Can't find the Shader/UVs tab

Do I really need to have a scientific explanation for my premise?

"One can do his homework in the library"

If the Captain's screens are out, does he switch seats with the co-pilot?

What does a stand alone "T" index value do?

Aliens englobed the Solar System: will we notice?

They call me Inspector Morse

Should I tell my boss the work he did was worthless

How to create a hard link to an inode (ext4)?

Are the terms "stab" and "staccato" synonyms?

Algorithm to convert a fixed-length string to the smallest possible collision-free representation?

Built-In Shelves/Bookcases - IKEA vs Built

Am I not good enough for you?

Examples of a statistic that is not independent of sample's distribution?

Grey hair or white hair

Extra alignment tab has been changed to cr. } using table, tabular and resizebox

Placing subfig vertically

Can someone explain what is being said here in color publishing in the American Mathematical Monthly?

Peter's Strange Word

Time travel short story where dinosaur doesn't taste like chicken

Is "history" a male-biased word ("his+story")?

Is there an equal sign with wider gap?

What wound would be of little consequence to a biped but terrible for a quadruped?

Making a sword in the stone, in a medieval world without magic



why my addition in php always update 2 in column at my database



2019 Community Moderator ElectionHow to secure database passwords in PHP?How do I see what character set a MySQL database / table / column is?MySQL query optimization - increase speed and efficiencyWhy shouldn't I use mysql_* functions in PHP?Cannot create new tables on the fly with EloquentGetting data from mysql query based on Date durationNeed help in SQL query performanceLaravel 5.3 eager loaded relations using method with()What is better in performance for 1-to-1 relationship: a new table or a VARCHAR column with a lot of empty entriesvoyager databases and MariaDB server










0















when im adding i always get the result of 2 what is wrong with my code please check it. table structure
table name = medicines_addeds



 1 idPrimary int(11) No None 
2 qty int(11) Yes NULL
3 xdate date Yes NULL
4 created_at timestamp Yes NULL
5 edited_at timestamp Yes NULL
6 deleted_at timestamp Yes NULL
7 med_id int(11) Yes NULL


table name = medicines



1 idPrimary int(11) No None 
2 name varchar(191) utf8_unicode_ci No None
3 description text utf8_unicode_ci Yes NULL
4 form varchar(191) utf8_unicode_ci Yes NULL
5 stocks int(11) Yes NULL
6 created_at timestamp Yes NULL
7 edited_at timestamp Yes NULL
8 deleted_at timestamp Yes NULL


code



if (isset($_POST['submit'])) 
else
header("Location: ../MIAdd_medicine.php");
exit();



i check if my input are right by using var_dump($_POST) and its fine so i think the error is in here please help me










share|improve this question



















  • 1





    The code stop execution after exit

    – Masivuye Cokile
    Mar 5 at 15:08











  • ohh yeah hahaha

    – Ken Verganio
    Mar 5 at 15:10











  • your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

    – Ken Verganio
    Mar 5 at 15:12











  • set stock = stock + $add

    – Masivuye Cokile
    Mar 5 at 15:13











  • it doesnt add up

    – Ken Verganio
    Mar 5 at 15:17















0















when im adding i always get the result of 2 what is wrong with my code please check it. table structure
table name = medicines_addeds



 1 idPrimary int(11) No None 
2 qty int(11) Yes NULL
3 xdate date Yes NULL
4 created_at timestamp Yes NULL
5 edited_at timestamp Yes NULL
6 deleted_at timestamp Yes NULL
7 med_id int(11) Yes NULL


table name = medicines



1 idPrimary int(11) No None 
2 name varchar(191) utf8_unicode_ci No None
3 description text utf8_unicode_ci Yes NULL
4 form varchar(191) utf8_unicode_ci Yes NULL
5 stocks int(11) Yes NULL
6 created_at timestamp Yes NULL
7 edited_at timestamp Yes NULL
8 deleted_at timestamp Yes NULL


code



if (isset($_POST['submit'])) 
else
header("Location: ../MIAdd_medicine.php");
exit();



i check if my input are right by using var_dump($_POST) and its fine so i think the error is in here please help me










share|improve this question



















  • 1





    The code stop execution after exit

    – Masivuye Cokile
    Mar 5 at 15:08











  • ohh yeah hahaha

    – Ken Verganio
    Mar 5 at 15:10











  • your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

    – Ken Verganio
    Mar 5 at 15:12











  • set stock = stock + $add

    – Masivuye Cokile
    Mar 5 at 15:13











  • it doesnt add up

    – Ken Verganio
    Mar 5 at 15:17













0












0








0








when im adding i always get the result of 2 what is wrong with my code please check it. table structure
table name = medicines_addeds



 1 idPrimary int(11) No None 
2 qty int(11) Yes NULL
3 xdate date Yes NULL
4 created_at timestamp Yes NULL
5 edited_at timestamp Yes NULL
6 deleted_at timestamp Yes NULL
7 med_id int(11) Yes NULL


table name = medicines



1 idPrimary int(11) No None 
2 name varchar(191) utf8_unicode_ci No None
3 description text utf8_unicode_ci Yes NULL
4 form varchar(191) utf8_unicode_ci Yes NULL
5 stocks int(11) Yes NULL
6 created_at timestamp Yes NULL
7 edited_at timestamp Yes NULL
8 deleted_at timestamp Yes NULL


code



if (isset($_POST['submit'])) 
else
header("Location: ../MIAdd_medicine.php");
exit();



i check if my input are right by using var_dump($_POST) and its fine so i think the error is in here please help me










share|improve this question
















when im adding i always get the result of 2 what is wrong with my code please check it. table structure
table name = medicines_addeds



 1 idPrimary int(11) No None 
2 qty int(11) Yes NULL
3 xdate date Yes NULL
4 created_at timestamp Yes NULL
5 edited_at timestamp Yes NULL
6 deleted_at timestamp Yes NULL
7 med_id int(11) Yes NULL


table name = medicines



1 idPrimary int(11) No None 
2 name varchar(191) utf8_unicode_ci No None
3 description text utf8_unicode_ci Yes NULL
4 form varchar(191) utf8_unicode_ci Yes NULL
5 stocks int(11) Yes NULL
6 created_at timestamp Yes NULL
7 edited_at timestamp Yes NULL
8 deleted_at timestamp Yes NULL


code



if (isset($_POST['submit'])) 
else
header("Location: ../MIAdd_medicine.php");
exit();



i check if my input are right by using var_dump($_POST) and its fine so i think the error is in here please help me







php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 5 at 16:15









Enzo BLANCHON

690317




690317










asked Mar 5 at 15:07









Ken VerganioKen Verganio

276




276







  • 1





    The code stop execution after exit

    – Masivuye Cokile
    Mar 5 at 15:08











  • ohh yeah hahaha

    – Ken Verganio
    Mar 5 at 15:10











  • your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

    – Ken Verganio
    Mar 5 at 15:12











  • set stock = stock + $add

    – Masivuye Cokile
    Mar 5 at 15:13











  • it doesnt add up

    – Ken Verganio
    Mar 5 at 15:17












  • 1





    The code stop execution after exit

    – Masivuye Cokile
    Mar 5 at 15:08











  • ohh yeah hahaha

    – Ken Verganio
    Mar 5 at 15:10











  • your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

    – Ken Verganio
    Mar 5 at 15:12











  • set stock = stock + $add

    – Masivuye Cokile
    Mar 5 at 15:13











  • it doesnt add up

    – Ken Verganio
    Mar 5 at 15:17







1




1





The code stop execution after exit

– Masivuye Cokile
Mar 5 at 15:08





The code stop execution after exit

– Masivuye Cokile
Mar 5 at 15:08













ohh yeah hahaha

– Ken Verganio
Mar 5 at 15:10





ohh yeah hahaha

– Ken Verganio
Mar 5 at 15:10













your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

– Ken Verganio
Mar 5 at 15:12





your right but when i add 12 in 2 the result is 13 then i try again and i add 3 then the result in database is 3

– Ken Verganio
Mar 5 at 15:12













set stock = stock + $add

– Masivuye Cokile
Mar 5 at 15:13





set stock = stock + $add

– Masivuye Cokile
Mar 5 at 15:13













it doesnt add up

– Ken Verganio
Mar 5 at 15:17





it doesnt add up

– Ken Verganio
Mar 5 at 15:17












1 Answer
1






active

oldest

votes


















0














Before your update query, your select query you should have a alias for the sum() it can be like this. I prefer prepared statement.



$sql1 = "select sum(stocks) AS total_sum from medicines where id = ?";
$result=$conn->prepare($sql1);
$result->bind_param("s", $Med_id);
$result->execute();
$result_0=$result->get_result();
while($row=$result_0->fetch_assoc()
$result_1=$row['total_sum'];

$add = $result_1+$Qty;





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55005837%2fwhy-my-addition-in-php-always-update-2-in-column-at-my-database%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Before your update query, your select query you should have a alias for the sum() it can be like this. I prefer prepared statement.



    $sql1 = "select sum(stocks) AS total_sum from medicines where id = ?";
    $result=$conn->prepare($sql1);
    $result->bind_param("s", $Med_id);
    $result->execute();
    $result_0=$result->get_result();
    while($row=$result_0->fetch_assoc()
    $result_1=$row['total_sum'];

    $add = $result_1+$Qty;





    share|improve this answer





























      0














      Before your update query, your select query you should have a alias for the sum() it can be like this. I prefer prepared statement.



      $sql1 = "select sum(stocks) AS total_sum from medicines where id = ?";
      $result=$conn->prepare($sql1);
      $result->bind_param("s", $Med_id);
      $result->execute();
      $result_0=$result->get_result();
      while($row=$result_0->fetch_assoc()
      $result_1=$row['total_sum'];

      $add = $result_1+$Qty;





      share|improve this answer



























        0












        0








        0







        Before your update query, your select query you should have a alias for the sum() it can be like this. I prefer prepared statement.



        $sql1 = "select sum(stocks) AS total_sum from medicines where id = ?";
        $result=$conn->prepare($sql1);
        $result->bind_param("s", $Med_id);
        $result->execute();
        $result_0=$result->get_result();
        while($row=$result_0->fetch_assoc()
        $result_1=$row['total_sum'];

        $add = $result_1+$Qty;





        share|improve this answer















        Before your update query, your select query you should have a alias for the sum() it can be like this. I prefer prepared statement.



        $sql1 = "select sum(stocks) AS total_sum from medicines where id = ?";
        $result=$conn->prepare($sql1);
        $result->bind_param("s", $Med_id);
        $result->execute();
        $result_0=$result->get_result();
        while($row=$result_0->fetch_assoc()
        $result_1=$row['total_sum'];

        $add = $result_1+$Qty;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 6 at 16:30









        marc_s

        581k13011211268




        581k13011211268










        answered Mar 5 at 15:58









        Kwaku amohKwaku amoh

        666




        666





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55005837%2fwhy-my-addition-in-php-always-update-2-in-column-at-my-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved