small sql query problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kzar
Forum Newbie
Posts: 16
Joined: Thu Nov 25, 2004 3:03 pm

small sql query problem

Post by kzar »

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';
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http://dev.mysql.com/doc/mysql/en/REPLACE.html

->

Code: Select all

REPLACE INTO `tt_lessons`
SET `TeacherID`='$lessonї$blockid]ї$subjectid]', `SubjectID`='$subjectid', `BlockID`='$blockid';
Post Reply