Jump to content


Photo

Inserting data with "where" condition?


  • Please log in to reply
5 replies to this topic

#1 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 12 July 2006 - 09:48 AM

hi, i would like to insert data with "where" condition is this correct codes
below?

$query = "INSERT INTO photos (comments) VALUES ('$comment_tmp') where ID = '91';

I want to insert the $comment_tmp into comments only on ID = 91.
Is this correct or wrong?
Please correct me if i'm wrong.

thank you very much in advance.


#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 12 July 2006 - 09:50 AM

I think you would want to use UPDATE here...

$query = "UPDATE photos SET comments='$comment_tmp' WHERE id='91';

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 July 2006 - 09:51 AM

You'll want to use an UPDATE statement rather than an INSERT statement. INSERT creates a new row into the database. Where as UPDATE can change fields within an existing row

#4 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 09:53 AM

yes update

#5 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 12 July 2006 - 10:13 AM

ok, i'll try that thanks!

#6 Newbiephper

Newbiephper
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 12 July 2006 - 03:01 PM

sry to use this post but it will get my point across

$query = "UPDATE photos SET comments='$comment_tmp' WHERE id='91';

what would happen if you wanted to use the 'id' from one table to update data in tanother table.

i.e. u have 2 tables

user data (this contains id)
table x ( you want to update data in this table for that particular user)

thx any help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users