Good health to all.

A question with SQL, such a code and for some reason does not make changes to the database.

$result2 = mysql_query ("UPDATE $userstable SET $userstable.Ostatok='$OST1', $userstable.Reserve='$REZ1' WHERE $userstable.Sklad_ID='T0001' and $userstable.ItemID='$ID'", $db); print("<br>остаток T0001:".$OST1." резерв:".$REZ1." skladID:".$skldID." ID товара:".$ID."<br>"); 

Fields are updateable DOUBLE format. Why does the seemingly obvious-correct query not UPDATE'it these fields?

  • This is not a query ... most likely, no connection was established with the database server. - Salivan
  • I see the names of tables and rows are set as variables, and these variables are given tables and rows ??? - webkostya
  • @Asen has not established a connection? O_o! This is something from: | - My TV is not working. | “Did you plug it in?” | - Yes! | - Hmm ..., | - And the fact that I turned off the light, this may not work? | - O_o !!!!!! - I_CaR
  • @Berserk I understand your thought, I will try. But this will not affect the functionality anyway. - I_CaR
  • @I_CaR Why do you replace the table names with variables at all, why is it not easier to simply enter the name of the table in the query or just the name of the string? - webkostya

3 answers 3

The first thing that catches your eye is again quotes (

 $result2 = mysql_query ("UPDATE $userstable SET $userstable.Ostatok='".$OST1."', $userstable.Reserve='".$REZ1."' WHERE $userstable.Sklad_ID='T0001' and $userstable.ItemID='".$ID."'", $db); 

And before executing the query, check if the data is contained in the variables involved in the query.

  • print ("<br> rest T0001:". $ OST1. ".... With this print, I check everything, everything is there. Ok, I will try your option, although the previous query for another table works with my version of quotes. - I_CaR
 $result2 = mysql_query ("UPDATE $userstable SET $userstable.Ostatok='$OST1', $userstable.Reserve='$REZ1' WHERE $userstable.Sklad_ID='T0001' and $userstable.ItemID='$ID'", $db) or die(mysql_error()); 

And then, even I would say THEN ONLY! Our inquiring minds will be able to understand the cause of the error!

    Strange, but that is what worked!

     //ЭТО работает!!! $result3 = mysql_query ("UPDATE $userstable3 SET $userstable3.Ostatok='$OST2' WHERE $userstable3.Sklad_ID='$skldID' and $userstable3.ItemID='$ID'", $db); 

    It takes even 3 seconds, SQL work is obvious

    And this:

     $result3 = mysql_query ("UPDATE $userstable3 SET $userstable3.Ostatok=".$OST2." WHERE $userstable3.Sklad_ID=".$skldID." and $userstable3.ItemID=".$ID."", $db); 

    It takes about 0.0249 seconds. and no changes in the database.