hi i m writing a program it is workng fine but doesnot update my database it gives me error since there are 4 query how can i know which one is wrong

my part of program is:

$query2="SELECT * FROM rpms WHERE product_name='$raw_material1'";
		  $result2=mysql_query($query2) or die(mysql_error());
		 if ($result2)
		 {
		 $row=mysql_fetch_assoc($result2);
		 $tot_quantity=$row['quantity']-$mat1_req;
		 }
		 
		 else {
		 echo "query for material1 failed";
		 }
		  
		    $query3="SELECT * FROM rpms WHERE product_name='$raw_material2'";
		  $result3=mysql_query($query3) or die(mysql_error());
		 if ($result3)
		 {
		 $row1=mysql_fetch_assoc($result3);
		 $tot_quantity1=$row1['quantity']-$mat2_req;
		 }
		 
		 else {
		 echo "query for material1 failed";
		 }
		 $query4= "UPDATE rpms SET quantity='$tot_quantity' WHERE product_name='$raw_material1' AND quantity='$tot_quantity1' WHERE product_name='$raw_material2'";
		 $result4= mysql_query($query4) or die(mysql_error());
		 
		 if ($result4)
		 {
		 echo " update successfully";
		 }
		 else
		 {
		 echo "updation failed";
		 }
		 		 $query5= "UPDATE rpms SET quantity='$tot_quantity1' WHERE product_name='$raw_material2'";
		 $result5= mysql_query($query5) or die(mysql_error());
		 
		 if ($result5)
		 {
		 echo " update successfully";
		 }
		 else
		 {
		 echo "updation failed";
		 }

?>

Recommended Answers

All 3 Replies

for debug just add an echo or print statment before the query

You might look into testing your queries in PHPmy Admin before you hard code them in PHP. Also, you might look into downloading and intalling MySQL workbench. MysQL workbench is great for testing queries as it evaluates the query for obvious errors as you type.

What is even better is you can test out really complex subqueries on it. It is free. It really helps a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.