Inventory count of my database keeps starting at 28?












0















I am new to coding and in my code and i am having trouble updating my database.
I am using mysql and php to create a shopping cart that updates inventory when an item is purchased. The cart takes the product id of the item and stores it using the GET array. The problem is that after someone purchases an item, the inventory doesn't adjust probably in my database. the inventory count always starts at 28 every time I purchase an item instead of starting at the proper inventory amount. The code for the shopping cart is:



require 'connect.php';
require 'item.php';
if(isset($_GET['id'])){
$result = mysqli_query($con, 'select * from products where
id='.$_GET['id']);
$products = mysqli_fetch_object($result);
$item = new Item();
$item->id = $products->id;
$item->name = $products->name;
$item->price = $products->price;
$item->quantity = 1;
$_SESSIONS['id']=$_GET['id'];
// Check if the products exists in the cart
$index = -1;
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++)
if($cart[$i]->id==$_GET['id'])
{
$index = $i;
break;
}
if($index==-1)
$_SESSION['cart'] = $item;
else{
$cart[$index]->quantity++;
$_SESSION['cart'] = $cart;
}


}



// Delete products in cart
if(isset($_GET['index'])){
$cart = unserialize(serialize($_SESSION['cart']));
unset($cart[$_GET['index']]);
$cart = array_values($cart);
$_SESSION['cart'] = $cart;
}

if(array_key_exists('submit2', $_POST))
{
$results = mysqli_query($con, "select * from products");
$sql="";//init
while($products=mysqli_fetch_object($results)){

for($i=0; $i<count($cart); $i++){
$idcart=$cart[$i]->id;
$quantity= $products->quantity;
$cartquantity = $cart[$i]-> quantity;
$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";//u need this to append the query
session_destroy(); }//end for
}//end while
if ($con->multi_query($sql) === TRUE) {//use multi_query
header("location: thankyou.php");
} else {
echo "Error updating record: " . $con->error;
}
$con->close();


I believe the problem is in this code here. $sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";. Any help will be appreciated. Thank you!










share|improve this question


















  • 4





    please use prepared statement for security purpose

    – suresh bambhaniya
    Nov 24 '18 at 17:34
















0















I am new to coding and in my code and i am having trouble updating my database.
I am using mysql and php to create a shopping cart that updates inventory when an item is purchased. The cart takes the product id of the item and stores it using the GET array. The problem is that after someone purchases an item, the inventory doesn't adjust probably in my database. the inventory count always starts at 28 every time I purchase an item instead of starting at the proper inventory amount. The code for the shopping cart is:



require 'connect.php';
require 'item.php';
if(isset($_GET['id'])){
$result = mysqli_query($con, 'select * from products where
id='.$_GET['id']);
$products = mysqli_fetch_object($result);
$item = new Item();
$item->id = $products->id;
$item->name = $products->name;
$item->price = $products->price;
$item->quantity = 1;
$_SESSIONS['id']=$_GET['id'];
// Check if the products exists in the cart
$index = -1;
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++)
if($cart[$i]->id==$_GET['id'])
{
$index = $i;
break;
}
if($index==-1)
$_SESSION['cart'] = $item;
else{
$cart[$index]->quantity++;
$_SESSION['cart'] = $cart;
}


}



// Delete products in cart
if(isset($_GET['index'])){
$cart = unserialize(serialize($_SESSION['cart']));
unset($cart[$_GET['index']]);
$cart = array_values($cart);
$_SESSION['cart'] = $cart;
}

if(array_key_exists('submit2', $_POST))
{
$results = mysqli_query($con, "select * from products");
$sql="";//init
while($products=mysqli_fetch_object($results)){

for($i=0; $i<count($cart); $i++){
$idcart=$cart[$i]->id;
$quantity= $products->quantity;
$cartquantity = $cart[$i]-> quantity;
$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";//u need this to append the query
session_destroy(); }//end for
}//end while
if ($con->multi_query($sql) === TRUE) {//use multi_query
header("location: thankyou.php");
} else {
echo "Error updating record: " . $con->error;
}
$con->close();


I believe the problem is in this code here. $sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";. Any help will be appreciated. Thank you!










share|improve this question


















  • 4





    please use prepared statement for security purpose

    – suresh bambhaniya
    Nov 24 '18 at 17:34














0












0








0








I am new to coding and in my code and i am having trouble updating my database.
I am using mysql and php to create a shopping cart that updates inventory when an item is purchased. The cart takes the product id of the item and stores it using the GET array. The problem is that after someone purchases an item, the inventory doesn't adjust probably in my database. the inventory count always starts at 28 every time I purchase an item instead of starting at the proper inventory amount. The code for the shopping cart is:



require 'connect.php';
require 'item.php';
if(isset($_GET['id'])){
$result = mysqli_query($con, 'select * from products where
id='.$_GET['id']);
$products = mysqli_fetch_object($result);
$item = new Item();
$item->id = $products->id;
$item->name = $products->name;
$item->price = $products->price;
$item->quantity = 1;
$_SESSIONS['id']=$_GET['id'];
// Check if the products exists in the cart
$index = -1;
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++)
if($cart[$i]->id==$_GET['id'])
{
$index = $i;
break;
}
if($index==-1)
$_SESSION['cart'] = $item;
else{
$cart[$index]->quantity++;
$_SESSION['cart'] = $cart;
}


}



// Delete products in cart
if(isset($_GET['index'])){
$cart = unserialize(serialize($_SESSION['cart']));
unset($cart[$_GET['index']]);
$cart = array_values($cart);
$_SESSION['cart'] = $cart;
}

if(array_key_exists('submit2', $_POST))
{
$results = mysqli_query($con, "select * from products");
$sql="";//init
while($products=mysqli_fetch_object($results)){

for($i=0; $i<count($cart); $i++){
$idcart=$cart[$i]->id;
$quantity= $products->quantity;
$cartquantity = $cart[$i]-> quantity;
$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";//u need this to append the query
session_destroy(); }//end for
}//end while
if ($con->multi_query($sql) === TRUE) {//use multi_query
header("location: thankyou.php");
} else {
echo "Error updating record: " . $con->error;
}
$con->close();


I believe the problem is in this code here. $sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";. Any help will be appreciated. Thank you!










share|improve this question














I am new to coding and in my code and i am having trouble updating my database.
I am using mysql and php to create a shopping cart that updates inventory when an item is purchased. The cart takes the product id of the item and stores it using the GET array. The problem is that after someone purchases an item, the inventory doesn't adjust probably in my database. the inventory count always starts at 28 every time I purchase an item instead of starting at the proper inventory amount. The code for the shopping cart is:



require 'connect.php';
require 'item.php';
if(isset($_GET['id'])){
$result = mysqli_query($con, 'select * from products where
id='.$_GET['id']);
$products = mysqli_fetch_object($result);
$item = new Item();
$item->id = $products->id;
$item->name = $products->name;
$item->price = $products->price;
$item->quantity = 1;
$_SESSIONS['id']=$_GET['id'];
// Check if the products exists in the cart
$index = -1;
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++)
if($cart[$i]->id==$_GET['id'])
{
$index = $i;
break;
}
if($index==-1)
$_SESSION['cart'] = $item;
else{
$cart[$index]->quantity++;
$_SESSION['cart'] = $cart;
}


}



// Delete products in cart
if(isset($_GET['index'])){
$cart = unserialize(serialize($_SESSION['cart']));
unset($cart[$_GET['index']]);
$cart = array_values($cart);
$_SESSION['cart'] = $cart;
}

if(array_key_exists('submit2', $_POST))
{
$results = mysqli_query($con, "select * from products");
$sql="";//init
while($products=mysqli_fetch_object($results)){

for($i=0; $i<count($cart); $i++){
$idcart=$cart[$i]->id;
$quantity= $products->quantity;
$cartquantity = $cart[$i]-> quantity;
$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";//u need this to append the query
session_destroy(); }//end for
}//end while
if ($con->multi_query($sql) === TRUE) {//use multi_query
header("location: thankyou.php");
} else {
echo "Error updating record: " . $con->error;
}
$con->close();


I believe the problem is in this code here. $sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';";. Any help will be appreciated. Thank you!







php mysql sql database shopping-cart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 17:29









harrisonharrison

153




153








  • 4





    please use prepared statement for security purpose

    – suresh bambhaniya
    Nov 24 '18 at 17:34














  • 4





    please use prepared statement for security purpose

    – suresh bambhaniya
    Nov 24 '18 at 17:34








4




4





please use prepared statement for security purpose

– suresh bambhaniya
Nov 24 '18 at 17:34





please use prepared statement for security purpose

– suresh bambhaniya
Nov 24 '18 at 17:34












3 Answers
3






active

oldest

votes


















1














The whole logic around updating the cart quantities seems to be unusual. You have a loop which loops over all of the products and then updates a somehow related database record based on the id from the cart with the quantity from the product. There is no attempt to match the quantity from the product ID with the ID from the cart.



This code just loops through the cart and reduces the quantity of the matching product for each row, it also prepares the statement before the loop and just executes it once for each row...



if(array_key_exists('submit2', $_POST))
{
$sql = "UPDATE products
SET quantity = quantity - ?
WHERE id= ?";
$stmt = $conn->prepare($sql);
foreach ( $cart as $item ){
$stmt->bind_param('ii', $item->quantity, $item->id );

$stmt->execute();
}//end foreach
session_destroy();
}//end if





share|improve this answer


























  • Thank you so much! This code worked perfectly!

    – harrison
    Nov 24 '18 at 18:43











  • This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

    – Nigel Ren
    Nov 24 '18 at 18:45



















1














You could use the quantity values directly in update



$sql = "UPDATE products SET quantity= quantity - ?  WHERE id= ? ;"
$stmt = $con->prepare($sql);
$stmt->bind_param('ii', $cartquantity, $idcart, );

$stmt->execute();





share|improve this answer
























  • Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

    – harrison
    Nov 24 '18 at 18:24











  • then check for the content of $idcart ..

    – scaisEdge
    Nov 24 '18 at 20:16



















-1














You forgot to concatenate your multi query sql on the line with this code:



$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Please put concat operator like this:



$sql .= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Or like this:



$sql= $sql."UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


I noticed you are executing your update SQL after loop which is fine but without concatenation you are only executing the last query in your loop.






share|improve this answer
























  • Don't do that. Use parameters in the query and bind values to them. See the other answers.

    – Shawn
    Nov 24 '18 at 20:44











  • That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

    – Anos K. Mhazo
    Nov 25 '18 at 21:04











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%2f53460688%2finventory-count-of-my-database-keeps-starting-at-28%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The whole logic around updating the cart quantities seems to be unusual. You have a loop which loops over all of the products and then updates a somehow related database record based on the id from the cart with the quantity from the product. There is no attempt to match the quantity from the product ID with the ID from the cart.



This code just loops through the cart and reduces the quantity of the matching product for each row, it also prepares the statement before the loop and just executes it once for each row...



if(array_key_exists('submit2', $_POST))
{
$sql = "UPDATE products
SET quantity = quantity - ?
WHERE id= ?";
$stmt = $conn->prepare($sql);
foreach ( $cart as $item ){
$stmt->bind_param('ii', $item->quantity, $item->id );

$stmt->execute();
}//end foreach
session_destroy();
}//end if





share|improve this answer


























  • Thank you so much! This code worked perfectly!

    – harrison
    Nov 24 '18 at 18:43











  • This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

    – Nigel Ren
    Nov 24 '18 at 18:45
















1














The whole logic around updating the cart quantities seems to be unusual. You have a loop which loops over all of the products and then updates a somehow related database record based on the id from the cart with the quantity from the product. There is no attempt to match the quantity from the product ID with the ID from the cart.



This code just loops through the cart and reduces the quantity of the matching product for each row, it also prepares the statement before the loop and just executes it once for each row...



if(array_key_exists('submit2', $_POST))
{
$sql = "UPDATE products
SET quantity = quantity - ?
WHERE id= ?";
$stmt = $conn->prepare($sql);
foreach ( $cart as $item ){
$stmt->bind_param('ii', $item->quantity, $item->id );

$stmt->execute();
}//end foreach
session_destroy();
}//end if





share|improve this answer


























  • Thank you so much! This code worked perfectly!

    – harrison
    Nov 24 '18 at 18:43











  • This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

    – Nigel Ren
    Nov 24 '18 at 18:45














1












1








1







The whole logic around updating the cart quantities seems to be unusual. You have a loop which loops over all of the products and then updates a somehow related database record based on the id from the cart with the quantity from the product. There is no attempt to match the quantity from the product ID with the ID from the cart.



This code just loops through the cart and reduces the quantity of the matching product for each row, it also prepares the statement before the loop and just executes it once for each row...



if(array_key_exists('submit2', $_POST))
{
$sql = "UPDATE products
SET quantity = quantity - ?
WHERE id= ?";
$stmt = $conn->prepare($sql);
foreach ( $cart as $item ){
$stmt->bind_param('ii', $item->quantity, $item->id );

$stmt->execute();
}//end foreach
session_destroy();
}//end if





share|improve this answer















The whole logic around updating the cart quantities seems to be unusual. You have a loop which loops over all of the products and then updates a somehow related database record based on the id from the cart with the quantity from the product. There is no attempt to match the quantity from the product ID with the ID from the cart.



This code just loops through the cart and reduces the quantity of the matching product for each row, it also prepares the statement before the loop and just executes it once for each row...



if(array_key_exists('submit2', $_POST))
{
$sql = "UPDATE products
SET quantity = quantity - ?
WHERE id= ?";
$stmt = $conn->prepare($sql);
foreach ( $cart as $item ){
$stmt->bind_param('ii', $item->quantity, $item->id );

$stmt->execute();
}//end foreach
session_destroy();
}//end if






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 18:39

























answered Nov 24 '18 at 18:25









Nigel RenNigel Ren

27.8k61933




27.8k61933













  • Thank you so much! This code worked perfectly!

    – harrison
    Nov 24 '18 at 18:43











  • This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

    – Nigel Ren
    Nov 24 '18 at 18:45



















  • Thank you so much! This code worked perfectly!

    – harrison
    Nov 24 '18 at 18:43











  • This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

    – Nigel Ren
    Nov 24 '18 at 18:45

















Thank you so much! This code worked perfectly!

– harrison
Nov 24 '18 at 18:43





Thank you so much! This code worked perfectly!

– harrison
Nov 24 '18 at 18:43













This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

– Nigel Ren
Nov 24 '18 at 18:45





This also shows how useful prepared statements can be, so worth spending a bit of time to learn something new.

– Nigel Ren
Nov 24 '18 at 18:45













1














You could use the quantity values directly in update



$sql = "UPDATE products SET quantity= quantity - ?  WHERE id= ? ;"
$stmt = $con->prepare($sql);
$stmt->bind_param('ii', $cartquantity, $idcart, );

$stmt->execute();





share|improve this answer
























  • Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

    – harrison
    Nov 24 '18 at 18:24











  • then check for the content of $idcart ..

    – scaisEdge
    Nov 24 '18 at 20:16
















1














You could use the quantity values directly in update



$sql = "UPDATE products SET quantity= quantity - ?  WHERE id= ? ;"
$stmt = $con->prepare($sql);
$stmt->bind_param('ii', $cartquantity, $idcart, );

$stmt->execute();





share|improve this answer
























  • Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

    – harrison
    Nov 24 '18 at 18:24











  • then check for the content of $idcart ..

    – scaisEdge
    Nov 24 '18 at 20:16














1












1








1







You could use the quantity values directly in update



$sql = "UPDATE products SET quantity= quantity - ?  WHERE id= ? ;"
$stmt = $con->prepare($sql);
$stmt->bind_param('ii', $cartquantity, $idcart, );

$stmt->execute();





share|improve this answer













You could use the quantity values directly in update



$sql = "UPDATE products SET quantity= quantity - ?  WHERE id= ? ;"
$stmt = $con->prepare($sql);
$stmt->bind_param('ii', $cartquantity, $idcart, );

$stmt->execute();






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 17:47









scaisEdgescaisEdge

95.5k105071




95.5k105071













  • Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

    – harrison
    Nov 24 '18 at 18:24











  • then check for the content of $idcart ..

    – scaisEdge
    Nov 24 '18 at 20:16



















  • Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

    – harrison
    Nov 24 '18 at 18:24











  • then check for the content of $idcart ..

    – scaisEdge
    Nov 24 '18 at 20:16

















Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

– harrison
Nov 24 '18 at 18:24





Thank you for your help! the inventory amounts are updating properly, but for some reason, it is now only updating the last item in my cart.

– harrison
Nov 24 '18 at 18:24













then check for the content of $idcart ..

– scaisEdge
Nov 24 '18 at 20:16





then check for the content of $idcart ..

– scaisEdge
Nov 24 '18 at 20:16











-1














You forgot to concatenate your multi query sql on the line with this code:



$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Please put concat operator like this:



$sql .= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Or like this:



$sql= $sql."UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


I noticed you are executing your update SQL after loop which is fine but without concatenation you are only executing the last query in your loop.






share|improve this answer
























  • Don't do that. Use parameters in the query and bind values to them. See the other answers.

    – Shawn
    Nov 24 '18 at 20:44











  • That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

    – Anos K. Mhazo
    Nov 25 '18 at 21:04
















-1














You forgot to concatenate your multi query sql on the line with this code:



$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Please put concat operator like this:



$sql .= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Or like this:



$sql= $sql."UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


I noticed you are executing your update SQL after loop which is fine but without concatenation you are only executing the last query in your loop.






share|improve this answer
























  • Don't do that. Use parameters in the query and bind values to them. See the other answers.

    – Shawn
    Nov 24 '18 at 20:44











  • That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

    – Anos K. Mhazo
    Nov 25 '18 at 21:04














-1












-1








-1







You forgot to concatenate your multi query sql on the line with this code:



$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Please put concat operator like this:



$sql .= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Or like this:



$sql= $sql."UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


I noticed you are executing your update SQL after loop which is fine but without concatenation you are only executing the last query in your loop.






share|improve this answer













You forgot to concatenate your multi query sql on the line with this code:



$sql= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Please put concat operator like this:



$sql .= "UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


Or like this:



$sql= $sql."UPDATE products SET quantity='$quantity' - ".$cartquantity." WHERE id='$idcart';"


I noticed you are executing your update SQL after loop which is fine but without concatenation you are only executing the last query in your loop.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 20:10









Anos K. MhazoAnos K. Mhazo

11516




11516













  • Don't do that. Use parameters in the query and bind values to them. See the other answers.

    – Shawn
    Nov 24 '18 at 20:44











  • That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

    – Anos K. Mhazo
    Nov 25 '18 at 21:04



















  • Don't do that. Use parameters in the query and bind values to them. See the other answers.

    – Shawn
    Nov 24 '18 at 20:44











  • That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

    – Anos K. Mhazo
    Nov 25 '18 at 21:04

















Don't do that. Use parameters in the query and bind values to them. See the other answers.

– Shawn
Nov 24 '18 at 20:44





Don't do that. Use parameters in the query and bind values to them. See the other answers.

– Shawn
Nov 24 '18 at 20:44













That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

– Anos K. Mhazo
Nov 25 '18 at 21:04





That is an inefficient query. Its not advised to run update query multiple times in loop unless you use transaction. No need to down-vote.

– Anos K. Mhazo
Nov 25 '18 at 21:04


















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%2f53460688%2finventory-count-of-my-database-keeps-starting-at-28%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen