gammaman Posted April 26, 2008 Share Posted April 26, 2008 what is wrong with this Update query <?php $conn=mysql_connect("localhost","fierm","13183"); if(!$conn){ echo "failed"; }else{ mysql_select_db(fierm); $Amt=$_POST['amt']; $Item=$_POST['new']; echo "$Amt"; echo "$Item"; $result=mysql_query("select InventoryLevel,ProductID from Inventory where ProductID='$Item' and '$Amt' < InventoryLevel"); $cou=mysql_num_rows($result); echo "$cou"; if ($cou > 0) { mysql_query("Update table Inventory set InventoryLevel = InventoryLevel-'$Amt' Where ProductID='$Item'"); } } ?> Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/ Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 table shouldn't be in the update query. by the way, php/mysql will give you a clue about the error if you use or die(mysql_error()): mysql_query($some_sql) or die(mysql_error() . " $some_sql"); Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/#findComment-527745 Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 First u can echo variable without double quotes: echo $amt; Second, as stated above theres no need to: "UPDATE table Inventory", just "UPDATE Inventory". Third im not sure about "set InventoryLevel = InventoryLevel-'$Amt'". U should calculate the difference in php and then update the db. Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/#findComment-527746 Share on other sites More sharing options...
gammaman Posted April 26, 2008 Author Share Posted April 26, 2008 You are right, I can't believe I missed that one. Will something like I have in the clause of this if stament work. <?php $conn=mysql_connect("localhost","fierm","13183"); if(!$conn){ echo "failed"; }else{ mysql_select_db(fierm); $Amt=$_POST['amt']; $Item=$_POST['new']; echo "$Amt"; echo "$Item"; $result=mysql_query("select InventoryLevel, ProductID from Inventory where ProductID='$Item'"); $cou=mysql_num_rows($result); echo "$cou"; if (InventoryLevel > $Amt ) { echo "<br/>"; echo "1"; mysql_query("Update Inventory set InventoryLevel = InventoryLevel-'$Amt' Where ProductID='$Item'"); } } ?> Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/#findComment-527747 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 what is InventoryLevel? there is no $ in front, so it must be a defined constant. Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/#findComment-527749 Share on other sites More sharing options...
gammaman Posted April 26, 2008 Author Share Posted April 26, 2008 InventoryLevel is one of the fields of my table. Link to comment https://forums.phpfreaks.com/topic/103030-help-with-basic-query/#findComment-527759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.