0
$get="SELECT dial_prod_total FROM dial_product WHERE dial_prod_id='$dpname'";
$idgen=mysql_query($get) or die(mysql_error());
$total=$idgen+$dpqty;
$dpbuy="UPDATE dial_product set dial_prod_total= '$total'".
       "WHERE dial_prod_id='$dpname'";
$result1=mysql_query($dpbuy) or die(mysql_error());

I want to get the data in the column dial_prod_total using the ID stored in $dpname and then update the value and store in the same column. The value is replaced in the column but it's not the correct value. What is the mistake I have made? Please help me.

3

2 Answers 2

1

Why don't you just do

UPDATE dial_product SET dial_prod_total = dial_prod_total + $dpqty
WHERE dial_prod_id = '$dpname'

Your code is vulnerable to injection. You should use properly parameterized queries with PDO or mysqli.

Sign up to request clarification or add additional context in comments.

8 Comments

it shows error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dial_prod_id = 'prod6'' at line 1"
@praveenrsmart dpqty is apparently an empty string
no its not. bec i am using it in two places.. when inserting into the first table i am getting the value, while updating alone i am getting problem
@praveenrsmart can you print out the whole query before you run it and show it to me?
$dpbuy="INSERT INTO dail_prod_buy(dial_prod_id,dial_dob,dail_prod_arrived,dial_buy_bill,dial_buy_cost)". "VALUES('$dpname','$dpdor','$dpcost','$dpqty','$dpdetail')"; $result=mysql_query($dpbuy) or die(mysql_error());
|
0

You query can be rebuild as below.

"UPDATE dial_product set dial_prod_total = dial_prod_total + ".$total." WHERE dial_prod_id = ".$dpname." ";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.