title: PHP AJAX - Uncaught PDOException: SQLSTATE[HY093], what is this?
body: <p>I looked around stackoverflow, there are lots of this kind of question. But I can't seem to find what is missing in the code.</p>
  <pre><code>Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\backend\cases\traffic\traffic-insert.php:95 Stack trace: #0 C:\xampp\htdocs\backend\cases\traffic\traffic-insert.php(95): PDOStatement-&gt;execute(Array) #1 C:\xampp\htdocs\router.php(51): include_once('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\router.php(9): route('/traffic-insert', '/backend/cases/...') #3 C:\xampp\htdocs\routes.php(24): post('/traffic-insert', '/backend/cases/...') #4 {main} thrown in C:\xampp\htdocs\backend\cases\traffic\traffic-insert.php on line 95
  </code></pre>
  <p>This error came after solving this: <br/>
  <a href="https://stackoverflow.com/questions/70179324/php-ajax-data-update-edit-inserts-as-new-data-instead-of-updating/70180190#70180190">PHP AJAX - data update/edit inserts as new data instead of updating</a></p>
  <p>Here is the code:</p>
  <pre><code>&lt;?php
  
  include('./backend/config/connection.php');
  include('./backend/config/function.php');
  
     if( isset($_POST[&quot;traffic_operation&quot;]) ) {
         if( $_POST[&quot;traffic_operation&quot;] == &quot;Add&quot; ) {
                $traffic_doc = '';
         
                if( $_FILES[&quot;traffic_doc&quot;][&quot;name&quot;] != '') {
                       $traffic_doc = upload_image();
                }
                $statement = $connection-&gt;prepare('INSERT INTO traffic_violations (
                       plateNumber,
                       carModel,
                       carColor,
                       violationType,
                       ownerGender,
                       violationDateTime,
                       violationLocation,
                       workingShift,
                       violationAction,
                       violationStatement,
                       cccEmployee
                ) VALUES (
                       :plate_number,
                       :car_model,
                       :car_color,
                       :violation_type,
                       :owner_gender,
                       :violation_date,
                       :violation_location,
                       :working_shift,
                       :violation_action,
                       :traffic_doc,
                       :ccc_employee
                       )
                ');
                $result = $statement-&gt;execute(
                       array(
                              ':plate_number' =&gt; $_POST[&quot;plate_number&quot;],
                              ':car_model' =&gt; $_POST[&quot;car_model&quot;],
                              ':car_color' =&gt; $_POST[&quot;car_color&quot;],
                              ':violation_type' =&gt; $_POST[&quot;violation_type&quot;],
                              ':owner_gender' =&gt; $_POST['owner_gender'],
                              ':violation_date' =&gt; $_POST['violation_date'],
                              ':violation_location' =&gt; $_POST['violation_location'],
                              ':working_shift' =&gt; $_POST['working_shift'],
                              ':violation_action' =&gt; $_POST['violation_action'],
                              ':traffic_doc' =&gt; $traffic_doc,
                              ':ccc_employee' =&gt; $_POST['ccc_employee']
                       )
                );
                       if( !empty($result) ) {
                              echo '&lt;script&gt;alert(&quot;Traffic Violation Added&quot;)&lt;/script&gt;';
                       }
         }
  
         if( $_POST[&quot;traffic_operation&quot;] == &quot;Edit&quot; ) {
                $traffic_doc = '';
  
                if( $_FILES[&quot;traffic_doc&quot;][&quot;name&quot;] != '') {
                       $traffic_doc = upload_image();
                } else {
                       $traffic_doc = $_POST['hidden_user_image'];
                }
  
                $statement = $connection-&gt;prepare('UPDATE traffic_violations SET
                       plateNumber = :plate_number,
                       carModel = :car_model,
                       carColor = :car_color,
                       violationType = :violation_type,
                       ownerGender = :owner_gender,
                       violationDateTime = :violation_date,
                       violationLocation = :violation_location,
                       workingShift = :working_shift,
                       violationAction = :violation_action,
                       violationStatement = :traffic_doc,
                       cccEmployee = :ccc_employee,
                       WHERE id = :id'
                       );
                       $statement-&gt;execute(
                              array(
                                     'id' =&gt; $_POST[&quot;violation_id&quot;],
                                     ':plate_number' =&gt; $_POST[&quot;plate_number&quot;],
                                     ':car_model' =&gt; $_POST[&quot;car_model&quot;],
                                     ':car_color' =&gt; $_POST[&quot;car_color&quot;],
                                     ':violation_type' =&gt; $_POST[&quot;violation_type&quot;],
                                     ':owner_gender' =&gt; $_POST['owner_gender'],
                                     ':violation_date' =&gt; $_POST['violation_date'],
                                     ':violation_location' =&gt; $_POST['violation_location'],
                                     ':working_shift' =&gt; $_POST['working_shift'],
                                     ':violation_action' =&gt; $_POST['violation_action'],
                                     ':traffic_doc' =&gt; $traffic_doc,
                                     ':ccc_employee' =&gt; $_POST['ccc_employee']
                              )
                       );
                       echo 'Traffic Violation Updated';
         }
     }
  ?&gt;
  </code></pre>