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. Quote Link to comment 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'; Quote Link to comment 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. Quote Link to comment 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) Quote Link to comment 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? Quote Link to comment 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'; Quote Link to comment Share on other sites More sharing options...
vigiw Posted July 10, 2007 Author Share Posted July 10, 2007 Why thank you for that link. 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.