0

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";
		 }

?>
4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by baruchM
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.