Page 1 of 1
I can't figure out why this isn't working (SQL Query)
Posted: Thu Jun 06, 2002 10:16 am
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 =)
Posted: Thu Jun 06, 2002 10:56 am
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'
Posted: Thu Jun 06, 2002 12:23 pm
by tarron
Thanks! The UPDATE query was what I was trying to go for. Everything worked.
Posted: Mon Aug 12, 2002 4:55 pm
by JPlush76
ah! I was just doing the same thing
update to the rescue, lol