tags:

views:

20

answers:

2

I have a PHP sql command that updates a record.

$tsql = "UPDATE cplinktable SET bmsid = $bmsid, autotaskid = $autotaskid, waspdb = $waspdb, cpid = $cpid WHERE id = $id";

I'm getting an error:

Invalid column name 'WaspTrackAsset_SFT'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid column name 'WaspTrackAsset_SFT'. ) )

Is there some reason that the value of waspdb is being used as a column?

thanks,

Jonesy

+1  A: 

Its a string field or varchar probably and you need it in single quotes. Like this:

$tsql = "UPDATE cplinktable SET bmsid = $bmsid, autotaskid = $autotaskid, waspdb = '$waspdb', cpid = $cpid WHERE id = $id"
John Hartsock
thanks! how embarrassing, I shoulda realised that!
iamjonesy
+3  A: 

If the variable is a string, SQL requires single quotes around it:

waspdb = '$waspdb'

Otherwise, it will look in the source row for a column with the name of the value of $wasdb. The reason why is perhaps most clearly illustrated with an example query:

update YourTable set col1 = 2*col2

This multiplies col2 by 2; it doesn't set col1 to '2*col2' :)

Andomar