Jump to content

Troubles updating a table


TBow

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.