I can't figure out why this isn't working (SQL Query)

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
tarron
Forum Newbie
Posts: 13
Joined: Thu May 23, 2002 12:09 pm

I can't figure out why this isn't working (SQL Query)

Post by tarron »

Code: Select all

$query ="INSERT into MY_TABLE VALUES ('$variable2', '$variable3') where ID = '$ID' ";
I'm trying to change fields 2 and 3 in a row with a unique identy increment who's current value is equal to $ID

all the rows in my database have an id# automatically assined by the DB, and I used a previous php script to call the row based on that id#. Now I want to go back and make a change to 2 fields in that row.. but my SQL query keeps spitting errors at me.


edit for syntax error =)
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

You need to include the names of the fields you want to insert into

INSERT into MY_TABLE(MY_FIELD2,MYFIELD3) VALUES ('$variable2','$variable3');

but as you are trying to use a where clause I have to ask how you can insert a record into a table where the ID = $ID when the record doesn't exist yet, I think you want to do an update

UPDATE MY_TABLE set MY_FIELD2='$var2', MY_FIELD3='$var3' where ID = '$ID'
tarron
Forum Newbie
Posts: 13
Joined: Thu May 23, 2002 12:09 pm

Post by tarron »

Thanks! The UPDATE query was what I was trying to go for. Everything worked.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

ah! I was just doing the same thing :)

update to the rescue, lol
Post Reply