Calling MySQL eggheads!

If you touch your software enough does it become hardware?

Moderator: Forum Moderators

Post Reply
ProfHawking
Zombie
Zombie
Posts: 2101
Joined: February 20th, 2005, 21:31

Calling MySQL eggheads!

Post 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!
Stoat
Site Admin
Site Admin
Posts: 3291
Joined: October 8th, 2004, 15:48
Location: Sheffield, UK
Contact:

Post 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'";
Fear
Zombie
Zombie
Posts: 2032
Joined: August 6th, 2006, 21:45

Post 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'
ProfHawking
Zombie
Zombie
Posts: 2101
Joined: February 20th, 2005, 21:31

Post 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!!! :x
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.
ProfHawking
Zombie
Zombie
Posts: 2101
Joined: February 20th, 2005, 21:31

Post 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! :boogie:
Post Reply