title: Using PHP/JS to perform actions
body: <p>to help teach myself PHP I've tasked myself with updating old mysql_* code with PDO. </p>
  
  <p>This has been going great, and as I've been learning I've been able to greatly reduce the amount of code. However my research has ran into a brick wall in a particular area.</p>
  
  <p>Currently, we have it so projects are recorded in a list view, with a set of 'actions/options' for each project. Each of these actions links to a PHP file which runs a small amount of code then sends you back to the list view.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>function projectComplete(id) {
      location.href = "complete.php?id=" + id;
  }
  
  &lt;button type="button" class="projectComplete" onclick="projectComplete('&lt;?= htmlentities($row['projectid']); ?&gt;')"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>The complete.php file simply contains an SQL update query that sets a column in the record a completed state of '1'.</p>
  
  <p>I originally wanted to ask the question 'what is the best practice for handling this type of interaction' however that may attract opinion based answers which I read is not allowed here.</p>
  
  <p>Instead I will phrase it like this: Is there a way of having all of these 'actions' run in the same page? (ideally able to use buttons rather than forms, due to difficulty in layout styling of forms)</p>
  
  <p>I know that if it used forms, I could simply name each form's submit button differently then run an if statement (the only issue would be passing the id, but I'm sure I could figure that out e.g.</p>
  
  <pre><code>if (isset($_POST['exampleAction'])) { Run the code.. }
  </code></pre>
  
  <p>Any links to guides/tutorials/similar questions etc would be very much appreciated. As previously stated, I'm self-learning PHP - I know very few 'best practices' and would like to learn more.</p>