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
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
|
show 6 more comments
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
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
|
show 6 more comments
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
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
php mysql
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
|
show 6 more comments
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
|
show 6 more comments
1 Answer
1
active
oldest
votes
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
edited Mar 6 at 16:30
marc_s
581k13011211268
581k13011211268
answered Mar 5 at 15:58
Kwaku amohKwaku amoh
666
666
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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