Page 1 of 1
Calling MySQL eggheads!
Posted: December 14th, 2007, 1:29
by ProfHawking
Please can i pick somebodys brains with some MySQL issues i am having...
I have a table - customers
and a field i need to update - lock
the row can be identified by a field called - name
i am trying to use
$sqlquery = "UPDATE `customers` SET `lock` = `$currentuser` WHERE `name` = `$name`";
but every way i try and do this, i get syntax errors or Database Error (1054): Unknown column '*name*' in 'where clause'
where *name* is the name of whatever customer i am trying to update.
Does anyone have a clue how to fix this?
Cheers in advance!
Posted: December 14th, 2007, 2:30
by Stoat
Is that your actual query? Because if it's in `slanty apostrophes` it will assume it's a database element rather than a string.
$sqlquery = "UPDATE `customers` SET `lock` = '$currentuser' WHERE `name` = '$name'";
Posted: December 14th, 2007, 3:05
by Fear
I don't do
MySQL that often as I work with the M$ varieties, but the little bit I have done I don't remember needing apostrophes except when sending a string.
Code: Select all
UPDATE customers
SET lock = $currentuser
WHERE name = '$name'
or
Code: Select all
UPDATE customers
SET lock = 1234
WHERE name = 'ProfHawking'
Posted: December 14th, 2007, 7:28
by ProfHawking
Stoat wrote:Is that your actual query? Because if it's in `slanty apostrophes` it will assume it's a database element rather than a string.
$sqlquery = "UPDATE `customers` SET `lock` = '$currentuser' WHERE `name` = '$name'";
Soo close! By using the slanty apostrophes on the column names and normal apostrophes on the variables then it no longer gives any errors:
$sqlquery = "UPDATE `customers` SET `lock` = '$currentuser' WHERE `name` = '$name'";
HOWEVER, it does not actually write anything into the database!!!
even though it has all the variables correct. If i print the query it comes back
UPDATE `customers` SET `lock` = 'rob' WHERE `name` = 'Maxnett Ltd'
Any ideas?
my old scripts used REPLACE INTO, is that a no longer supported method?
Fear wrote:I don't do
MySQL that often as I work with the M$ varieties, but the little bit I have done I don't remember needing apostrophes except when sending a string.
Code: Select all
UPDATE customers
SET lock = $currentuser
WHERE name = '$name'
or
Code: Select all
UPDATE customers
SET lock = 1234
WHERE name = 'ProfHawking'
This doesn't work im afraid, it must need some kind of separating, otherwise it gives a syntax error.
Posted: December 14th, 2007, 7:40
by ProfHawking
ah! cracked it.
THanks stoat! got that one working. I figured as it didnt error the sql must be correct.
On rechecking everything i remembered that the lock was set to be an INT not a VARCHAR, as i changed the way i was going to do it. doh!
Anyway, i can move on now, cheers!