vigiw Posted July 10, 2007 Share Posted July 10, 2007 Hello, I have a PHP form sending data to a MySQL table, and I am wondering if I can add some sort of code to the PHP page that will make the form data overwrite any potentially old data already in the table. This sounds simple enough, but I can't put my finger on it. ??? Thanks. Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/ Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 Use an UPDATE statement. eg; UPDATE tbl SET fld = 'new data'; Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294501 Share on other sites More sharing options...
vigiw Posted July 10, 2007 Author Share Posted July 10, 2007 Oh of course, update... But... Can I replace the following "Insert Into": $sql = "INSERT INTO `" . $table_name . "` to just Update Because after that line, i have all the fields listed, there is a number of them. Thanks. Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294503 Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 No. The syntax for an UPDATE is different to an INSERT. (As shown above) Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294508 Share on other sites More sharing options...
vigiw Posted July 10, 2007 Author Share Posted July 10, 2007 Ok, so with this-- UPDATE tbl SET fld = 'new data'; Should I replace the insert commands with-- $sql = "UPDATE" . "$table_name" SET field1 = 'new data'; $sql = "UPDATE" . "$table_name" SET field2 = 'new data'; and so on for each field? Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294514 Share on other sites More sharing options...
trq Posted July 10, 2007 Share Posted July 10, 2007 There is such a thing as the mysql manual. Simply put, you can use.... $sql = "UPDATE $table_name SET field1 = 'new data', fld2 = 'new data'; Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294519 Share on other sites More sharing options...
vigiw Posted July 10, 2007 Author Share Posted July 10, 2007 Why thank you for that link. Link to comment https://forums.phpfreaks.com/topic/59289-php-form-overwrites-mysql-table-data/#findComment-294525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.