Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
kzar
Forum Newbie
Posts: 16 Joined: Thu Nov 25, 2004 3:03 pm
Post
by kzar » Sun Jan 02, 2005 5:05 am
I'm trying to write a query that overwrites / adds a record, but I keep getting this error.
Code: Select all
You have an error in your SQL syntax near 'WHERE `SubjectID`='1' AND `BlockID`='3'' at line 3
Here is my query
Code: Select all
REPLACE INTO `tt_lessons`
SET `TeacherID`='$lessonї$blockid]ї$subjectid]'
WHERE `SubjectID`='$subjectid'
AND `BlockID`='$blockid';
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 02, 2005 6:48 am
I'm pretty sure you aren't getting the finalized string you think you are. Try printing it out and seeing what is being sent to the database.
kzar
Forum Newbie
Posts: 16 Joined: Thu Nov 25, 2004 3:03 pm
Post
by kzar » Sun Jan 02, 2005 9:25 am
I am printing already, im pretty sure its all ok. I'm pretty stumped though. I remobed the last two lines of the query that it complains about and then it didn't throw an error so its definately a problem with those.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 02, 2005 10:45 am
oops, I forgot there's no WHERE clauses in [mysql_man]REPLACE[/mysql_man] syntax.
kzar
Forum Newbie
Posts: 16 Joined: Thu Nov 25, 2004 3:03 pm
Post
by kzar » Sun Jan 02, 2005 2:12 pm
damn, I read a little example on this forum with one because I don't really understand the official page. Is there a different way of doing this then?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 02, 2005 2:14 pm
what's wrong with using [mysql_man]UPDATE[/mysql_man]?
kzar
Forum Newbie
Posts: 16 Joined: Thu Nov 25, 2004 3:03 pm
Post
by kzar » Sun Jan 02, 2005 2:24 pm
The problem with update is that it has to exist. I wanted to use replace so that it would make the entry if it existed or not.