Im trying to update a value in MySQL, to increase a number.Lets say that current value is 50, and if I will type 50 in the text-box, mysql value to become 100. Actually with the code below its only updating with the current text-box value.
- function updateMaterial($code){
- global $conn;
- $sql = $conn->prepare("SELECT * FROM stock WHERE itemcode = '$code'");
- $sql->execute();
- while($row = $sql->fetch(PDO::FETCH_ASSOC)){
- $this->id = $row['id'];
- }
- if(isset($_POST['qty'])){
-
- $sql = $conn->prepare("UPDATE stock SET qty='qty +$this->qty' WHERE id='$this->id'");
- $sql->execute();
-
- }
-
- }
-
- if(isset($_POST['update'])){
- $code = $_POST['itemcode'];
- if($addstock->updateMaterial($code)){
- return true;
- }else{
- return false;
- }
- }