title: Delete Row Using PHP Postgres
body: <p>could someone help on below code? I have table data on that can allow user to click button to delete the row. I got error said " Undefined index: tenant_id " , Undefined variable: row.  Below are delete.php and pg-t-payment-view.php script : </p>
  
  <pre><code>            &lt;?php  
              $db = pg_connect("host=10.0.32.204 port=5432 dbname=postgres user=postgres password=postgres"); 
              $id = $_POST['tenant_id'];
  
              $sql2 ="DELETE FROM payment_ref_tenancy WHERE tenant_name = '$id'";
  
              $result = pg_query($sql2);
              $cmdtuples = pg_affected_rows($result);
              echo $cmdtuples . " record affected.\n";
              if (!$result) {
                  $errormessage = pg_last_error();
                  echo "Error with query: " . $errormessage;
                  exit();
              }
              pg_close();
  
              header('location:pg-t-payment-view.php');
  
              ?&gt;
  </code></pre>
  
  <p>-------------pg-t-payment-view.php script</p>
  
  
  
  <pre><code>          &lt;div class="box-body table-responsive no-padding"&gt;
               &lt;?php  
              $db = pg_connect("host=10.0.32.204 port=5432 dbname=postgres user=postgres password=postgres"); 
              $sql2 ="select tenant_id,to_char(last_update_time, 'MM-dd-yyyy HH24:MI') as last_update_time , tenant_name, tenant_cost_category, invoice_no,tenant_agreed_cost,
              to_char(submission_date, 'MM-dd-yyyy') as submission_date,to_char(cpr_submission_to_finance, 'MM-dd-yyyy') as cpr_submission_to_finance,io,cheque_no 
              FROM payment_ref_tenancy order by insert_datetime desc limit 10";
  
              $result = pg_query($db,$sql2);
              if (!$result) {
                  $errormessage = pg_last_error();
                  echo "Error with query: " . $errormessage;
                  exit();
              }
              pg_close();
  
                  echo "&lt;table class='table table-hover table-striped'&gt;";
                  echo "&lt;th align='center' &gt;Date&lt;/th&gt;";
                  echo "&lt;th align='center' &gt;Payee&lt;/th&gt;";
                  echo "&lt;th align='center' &gt;Category&lt;/th&gt;";
                  echo "&lt;th align='center' &gt;Cost (RM)&lt;/th&gt;";
                  echo "&lt;th align='center' &gt;Invoice No&lt;/th&gt;";
                  echo "&lt;th align='center' &gt;Payment Submission Date&lt;/th&gt;";
                  echo "&lt;th align='center'&gt;CPR Submission to Finance&lt;/th&gt;";
                  echo "&lt;th align='center'&gt;IO&lt;/th&gt;";
                  echo "&lt;th align='center'&gt;Cheque No&lt;/th&gt;";
                  echo "&lt;th align='center' div style ='color:#ff0000'&gt;Action&lt;/th&gt;"; 
                  echo "&lt;th align='center'&gt;&lt;/th&gt;";
                  echo "&lt;th align='center'&gt;&lt;/th&gt;";
  
  
                  while($row=pg_fetch_assoc($result))
                  { $id = $row['tenant_id'];
  
                  echo "&lt;tr&gt;";                                
                  echo "&lt;td&gt;" . $row['last_update_time'] . "&lt;/td&gt;"; 
                  echo "&lt;td&gt;" . $row['tenant_name'] . "&lt;/td&gt;";  
                  echo "&lt;td&gt;" . $row['tenant_cost_category'] . "&lt;/td&gt;";  
                  echo "&lt;td&gt;" . $row['tenant_agreed_cost'] . "&lt;/td&gt;";  
                  echo "&lt;td&gt;" . $row['invoice_no'] . "&lt;/td&gt;";  
                  echo "&lt;td&gt;" . $row['submission_date'] . "&lt;/td&gt;";
                  echo "&lt;td&gt;" . $row['cpr_submission_to_finance'] . "&lt;/td&gt;";
                  echo "&lt;td&gt;" . $row['io'] . "&lt;/td&gt;";
                  echo "&lt;td&gt;" . $row['cheque_no'] . "&lt;/td&gt;";
  
                  echo  "&lt;td&gt;&lt;a href='pg-t-payment-edit.php'&gt;Edit&lt;/a&gt;&lt;/td&gt;";
  
                  echo  "&lt;td&gt;&lt;a href='delete.php?id=$id'&gt;&lt;input type='hidden' name='id' value=$id&gt;Delete&lt;/a&gt;&lt;/td&gt;";  
                  echo "&lt;/tr&gt;";} 
                  echo "&lt;/table&gt;";
  </code></pre>
  
  <p>?> 
                  </p>