title: PHP getting an automated sql data to be deleted
body: <p>I've been asked to create a Timesheet based on PHP and mySQL.</p>
  
  <p>I've created a page to insert the data and another page to show the data and edit/delete the data shown.</p>
  
  <p>Here is the page to show the data and edit/delete them:</p>
  
  <pre><code>&lt;?php
      while($info = mysql_fetch_array( $data )) {
  ?&gt;
  &lt;tr&gt;
      &lt;td&gt; &lt;input type="checkbox" name="job" id="&lt;?php echo $info['job_code']?&gt;" value="&lt;?php echo $info['job_code']?&gt;" /&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_code'] ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_desc'] ?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_client'] ?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_year'] ?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_month']?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_date']?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo $info['job_category']?&gt; &lt;/td&gt;
      &lt;td&gt;EDIT&lt;/td&gt;
      &lt;td&gt;DELETE&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>and here's the deleting process</p>
  
  <pre><code> $this-&gt;db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  
  $admin_data_query = mysql_query("SELECT * FROM jobs")or die(mysql_error());
  $job_code_query = $_POST['job'];
  $job_code_query_items = 'IN ( ';
  foreach ($job_code_query as $key =&gt; $value) {
      $job_code_query_items .= ($key &gt; 0 ? ", '" . $value . "'" : "'" . $value . "'");
  }
  $job_code_query_items .= ' );';
  while ($admin_data = mysql_fetch_array($admin_data_query)) {
      if (isset($_POST[$admin_data['job_code']])) {
          $admin_sql = "DELETE FROM jobs WHERE job_code = $job_code_query_items";
          $admin_query = mysql_query($admin_sql) or die(mysql_error());
          $this-&gt;messages[] = "Job deleted.";
      } else {
          $this-&gt;messages[] = "Failed to delete job.";
      }
  }
  </code></pre>
  
  <p>From my understanding, the variable of job[] in the 2nd page didn't catch the user submitted checkbox in page 1, or the first page didn't send the data because the checkbox value(maybe i wrote it wrong)</p>
  
  <p>EDIT: I've found the answer, here are the correct code:</p>
  
  <p>in page 1</p>
  
  <pre><code>&lt;td&gt;
      &lt;input type="checkbox" name="&lt;?php echo $info['job_code']?&gt;"
             id="&lt;?php echo $info['job_code']?&gt;"
             value="&lt;?php echo $info['job_code']?&gt;"/&gt;
  &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_code'] ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_desc'] ?&gt; &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_client'] ?&gt; &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_year'] ?&gt; &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_month']?&gt; &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_date']?&gt; &lt;/td&gt;
  &lt;td&gt;&lt;?php echo $info['job_category']?&gt; &lt;/td&gt;
  </code></pre>
  
  <p>in processing page (2)</p>
  
  <pre><code> while ($admin_data = mysqli_fetch_array($admin_data_query)) {
      $job_code_query = $admin_data["job_code"];
  
      if (isset($_POST[$admin_data["job_code"]])) {
  
          $admin_sql = "DELETE FROM jobs WHERE job_code = '$job_code_query'";
          $admin_query = mysqli_query($this-&gt;db_connection, $admin_sql) or die(mysqli_error($this-&gt;db_connection));
          $this-&gt;messages[] = "Job deleted.";
      } else {
          $this-&gt;messages[] = "Failed to delete job.";
      }
  }
  </code></pre>
  
  <p>Thank you for anyone who have tried to help or read it!</p>