0

I want to insert data into returnlist table and update the material table when i click the insert button. insertion works fine but the material table doesn't get updated.

<?php

    if(isset($_POST['submit'])){


    $Item = $_POST['Item'];
    $Quantity = $_POST['Quantity'];
    $Location = $_POST['Location'];
    $ReDate = $_POST['ReDate'];

    $query = mysql_query("INSERT INTO returnlist(Item,Quantity,Location,ReDate) VALUES ('$Item','$Quantity','$Location' ,'$ReDate')",$connection);
    $query = mysql_query("UPDATE material SET Quantity=Quantity + '$Quantity' WHERE 'Item'='$Item'", $connection);
    }

?>       
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lisa234
  • 81
  • 8
  • More clarity is needed. When you click the button, do you send your request over ajax? – Oniya Daniel Oct 06 '17 at 05:38
  • Assuming that the query is correct, have you check `$item`'s value if it is really what you expect? Or at least tried the query in `phpmyadmin` *(if you are using it)* ? – Carl Binalla Oct 06 '17 at 05:39
  • One more thing, if you are using variables inside a string, use `"` rather than `'`, so that the variable's value is used rather than using it literally – Carl Binalla Oct 06 '17 at 05:40
  • Please don't use mysql_* . Either use mysqli or pdo. This has been repeated soo many times. Also never go live in production with this 'code'. It's amazing nobody is talking about the massive security vulnerabilities in the above code – Rotimi Oct 06 '17 at 05:41
  • You need to concatenate the data values with the Sql string values. – Tuhin Subhra Dey Oct 06 '17 at 05:42

2 Answers2

3

try this format

$query = mysql_query("UPDATE material SET `Quantity` = `Quantity` + '".$Quantity."' WHERE `Item` = '".$Item."'", $connection);
AZinkey
  • 5,209
  • 5
  • 28
  • 46
0

Remove single quote from item and change it to backtick.

UPDATE material SET Quantity=Quantity + '$Quantity' WHERE 'Item'='$Item'

change to use backtick

"UPDATE material SET Quantity=Quantity + '$Quantity' WHERE `Item`='$Item'"

or remove it

"UPDATE material SET Quantity=Quantity + '$Quantity' WHERE Item='$Item'"
Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40