TBow Posted April 8, 2010 Share Posted April 8, 2010 I can not figure out what I am doing wrong. I have a license table that has all of our license in it. I am wanting to select a record where the OrderID = 0 and the LicenseTypeID is equal to the LicID. The LicID is from a the products page which ties the license to that product. I am not getting any errors, but it is updating the first record where the OrderID = 0 but it ignores the LicenseTypeID. <?php // BEGIN EDIT $PHPSESSID = session_id(); $bw_LicID = $Xpresso->DisplayInfo("LicID"); mysql_select_db($database_XpressoConnection, $XpressoConnection); $sql = "BEGIN WORK; SELECT LicenseTypeID, OrderID FROM Licenses WHERE LicenseTypeID =$bw_LicID and OrderID ='0' FOR UPDATE; ROLLBACK; UPDATE Licenses SET Orderid = [sessionID]; COMMIT;"; $result = mysql_query($sql, $XpressoConnection); ?> The LicenseTypeID's in the Licenses table start with 4 and go through 28. It is picks the first record with OrderID = 0 and LicenseTypeID = 4 even when I changed the code to <?php // BEGIN EDIT $PHPSESSID = session_id(); //$bw_LicID = $Xpresso->DisplayInfo("LicID"); mysql_select_db($database_XpressoConnection, $XpressoConnection); $sql = "BEGIN WORK; SELECT LicenseTypeID, OrderID FROM Licenses WHERE LicenseTypeID ='5' and OrderID ='0' FOR UPDATE; ROLLBACK; UPDATE Licenses SET Orderid = [sessionID]; COMMIT;"; $result = mysql_query($sql, $XpressoConnection); ?> If I query SELECT LicenseTypeID, OrderID FROM Licenses WHERE LicenseTypeID ='5' and OrderID ='0' it works. I am sure it is something simple, but I am fairly new to all this. Any help is greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/197964-troubles-updating-a-table/ Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2010 Share Posted April 8, 2010 Granted I'm not an expert on transactions, but what I see is you run a select query with the WHERE parameters, then an UPDATE without WHERE parameters, and without LIMIT. Seems to me it would update all records, setting OrderID to the value of $SessionId. Like I said, I don't know much about transaction, but that query string looks off to me. Link to comment https://forums.phpfreaks.com/topic/197964-troubles-updating-a-table/#findComment-1038795 Share on other sites More sharing options...
TBow Posted April 8, 2010 Author Share Posted April 8, 2010 Solved!!! When I read your comment I knew right away what was going on! Must have been working on it too long and went brain dead! Link to comment https://forums.phpfreaks.com/topic/197964-troubles-updating-a-table/#findComment-1039155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.