Jump to content


Photo

Editing database table rows


  • Please log in to reply
6 replies to this topic

#1 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 12:26 AM

I have searched this but for some reason I cannot find out how to do this.

I've managed to script the control panel so that I can add things in. Easy: INSERT INTO

However, could someone tell me how to script it so that I can edit a row?
I mean I can select the row from the database and have the data inside of form fields. But when I click submit, how would I make it so that it will edit and replace the row fields with what is in each of the form fields.

Thanks

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 August 2006 - 12:28 AM

UPDATE tablename SET field1 = 'newvalue', field2 = 'newvalue' WHERE idfield = 'identifier'

http://dev.mysql.com.../en/update.html

#3 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 12:35 AM

im confused by what you wrote

Say for instance im updating and replacing the fields Name, Tariff and Image in the table phone_tariffs. (examples)

What would the code be.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 12:39 AM

UPDATE phone_tarrifs SET `Name`='newvalue', Tariff='newvalue', Image='newvalue' WHERE id='identifier'

Note the id column stipulated in the WHERE clause. You need a unique key to be able to locate the exact record to update.

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 August 2006 - 12:39 AM

UPDATE phone_tariffs SET Name = 'newname', Tariff = 'newtariff', Image = 'newimage WHERE idfield = 'identifier'

idfield would be your primary key.

#6 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 17 August 2006 - 12:41 AM

UPDATE phone_tariffs SET Name = '$name', Tariff = '$tariff', Image = '$image';

BUT if you just did that it woudl up date EVERY record in you database so make sure you use the WHERE cluase if you only want to update certain records.

UPDATE phone_tariffs SET Name = '$name', Tariff = '$tariff', Image = '$image' WHERE Id = '$id'

Will ensure you only update the row(s) where Id = the ste value.
follow me on twitter @PHPsycho

#7 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 17 August 2006 - 12:42 AM

Thanks guys :) Very helpful site this place is!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users