gammaman Posted April 26, 2008 Share Posted April 26, 2008 Is there anything wrong with what I am trying to do, because it seems that the elseif or else are never reached. The if (first statment) works fine. <?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 from Inventory where ProductID='$Item'AND InventoryLevel"); $cou=mysql_num_rows($result); echo "$cou"; if (InventoryLevel > $Amt ) { mysql_query("Insert into CustomerOrder (ProductID,Amount) Values ('$Item','$Amt')")or die(mysql_error()); mysql_query("Update Inventory set InventoryLevel = InventoryLevel-'$Amt' Where ProductID='$Item'"); } elseif (InventoryLevel == $Amt ) { mysql_query("Insert into CustomerOrder (ProductID,Amount) Values ('$Item','$Amt')")or die(mysql_error()); mysql_query("Delete From Inventory ProductID,Amount where ProductID='$Item' and Amount='$Amt'"); } else { echo "Sorry Not Enough Items"; } } ?> Link to comment https://forums.phpfreaks.com/topic/103042-anything-wrong-with-if-else-structure/ Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 you seem to expect InventoryLevel to contain a value, but it doesn't. you'll have to pull the value from $result using mysql_fetch_array() or similar. list($InventoryLevel) = mysql_fetch_row($result); if ($InventoryLevel > $Amt ) { etc... Link to comment https://forums.phpfreaks.com/topic/103042-anything-wrong-with-if-else-structure/#findComment-527799 Share on other sites More sharing options...
gammaman Posted April 26, 2008 Author Share Posted April 26, 2008 thanks, did not know you could assign variable to a query Field. It works now. Link to comment https://forums.phpfreaks.com/topic/103042-anything-wrong-with-if-else-structure/#findComment-527801 Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 Dont open a new thread for every minor problems u have in the same code. U have posted this code already in here. Link to comment https://forums.phpfreaks.com/topic/103042-anything-wrong-with-if-else-structure/#findComment-527808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.