Jump to content

Archived

This topic is now archived and is closed to further replies.

Nothadoth

Editing database table rows

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]UPDATE tablename SET field1 = 'newvalue', field2 = 'newvalue' WHERE idfield = 'identifier'[/code]

http://dev.mysql.com/doc/refman/5.1/en/update.html

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[code]
UPDATE phone_tarrifs SET `Name`='newvalue', Tariff='newvalue', Image='newvalue' WHERE id='identifier'
[/code]

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

Share this post


Link to post
Share on other sites
[code]UPDATE phone_tariffs SET Name = 'newname', Tariff = 'newtariff', Image = 'newimage WHERE idfield = 'identifier'[/code]

idfield would be your primary key.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.