Nothadoth Posted August 17, 2006 Share Posted August 17, 2006 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 INTOHowever, 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 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 [code]UPDATE tablename SET field1 = 'newvalue', field2 = 'newvalue' WHERE idfield = 'identifier'[/code]http://dev.mysql.com/doc/refman/5.1/en/update.html Quote Link to comment Share on other sites More sharing options...
Nothadoth Posted August 17, 2006 Author Share Posted August 17, 2006 im confused by what you wroteSay for instance im updating and replacing the fields Name, Tariff and Image in the table phone_tariffs. (examples)What would the code be. Quote Link to comment Share on other sites More sharing options...
trq Posted August 17, 2006 Share Posted August 17, 2006 [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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 [code]UPDATE phone_tariffs SET Name = 'newname', Tariff = 'newtariff', Image = 'newimage WHERE idfield = 'identifier'[/code]idfield would be your primary key. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 17, 2006 Share Posted August 17, 2006 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. Quote Link to comment Share on other sites More sharing options...
Nothadoth Posted August 17, 2006 Author Share Posted August 17, 2006 Thanks guys :) Very helpful site this place is! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.