title: What is the best practice to update / edit form fields in php and mysql?
body: <p>This may sound like a typical question, but I wasn't able to find decent answers on stackoverflow. I've already built adding and deleting items from the php form. Let's say I have a simple structure like this:</p>
  
  <p><strong>Database</strong></p>
  
  <pre><code>|car_id(PK)|year  |   make   |   model   |  vin  |
  --------------------------------------------------
  |   1      | 2001 |  toyota  |  corolla  | 12345 |
  |   2      | 1999 |  ford    |  fiesta   | 67890 |
  |   3      | 2013 |  gmc     |  yukon    | abcde |
  </code></pre>
  
  <p><strong>Car Class</strong></p>
  
  <pre><code>class Car
  {
     public car_id;
     public year;
     public make;
     public model;
     public vin; //unique, can only be one in DB
  
     function addCar(){...}
     function editCar(){...}
     function deleteCar(){...}
  }
  </code></pre>
  
  <p><strong>PHP: cars.php?do=edit</strong></p>
  
  <p>This is where I want to run functions from the class and display templates using smarty</p>
  
  <p><strong>Viewer edit_cars.html</strong></p>
  
  <p>When this page loads, it pulls all values from DB and creates forms with values already in them, user can overwrite the values or delete them.</p>
  
  <p><strong>Question 1:</strong>
  Where should I check if vin(vehicle identification number, can only be one unique number in the database) matches the car already exists in the system? Car class or cars.php?</p>
  
  <p><strong>Question 2:</strong>
  What is the best way to update records?</p>
  
  <ol>
  <li>delete row and insert new one?</li>
  <li>update ALL values, even if they didn't change</li>
  <li>check fields that are different using javascript? (on change check
  values, if changed set some kind of var in PHP)</li>
  <li>check fields that are different using php? (select old values and
  match them against form values after submit) Use some kind of PHP
  function to only update fields that changed</li>
  </ol>
  
  <p><strong>Question 3:(this is more of a concern to me)</strong>
  After user submits the form, what should I do with their input:</p>
  
  <ol>
  <li>when user leaves values as is and nothing has changed</li>
  <li>when user deletes the value completely(such as "Make")</li>
  <li>when user ONLY changes the letter from lower case to upper</li>
  </ol>
  
  <p>I know these are a lot of questions, but I'm pretty sure a lot of people would benefit from this in the future when they are searching for these type of stuff.</p>
  
  <p>Thank you so much for your answers</p>