html - DELETE record in a row in PHP -


i trying delete record on database. created table contains of records. need when click on "delete" link delete record selected row.

here's looks like:

so have 3 pages here.
1. page.php
2. add.php
3. delete.php

here's page.php file:

<table border="1">     <thead>         <th>email</th>         <th>date</th>         <th>delete</th>     </thead>      <tbody>         <tr>         <?php              foreach($emails $mail){ ?>             <td><?php echo $mail['email']; ?></td>             <td><?php echo $mail['date']; ?></td>             <td><?php echo "<a href='delete.php?id=". $mail['id']. "'>delete</a>"; ?></td>         </tr>             <?php } ?>       </tbody> </table> 

here's add.php file:

<?php     require("new-connection.php");      session_start();      $email = $_post['email'];     if(empty($_post['email']) , (filter_var($email, filter_validate_email) === false))      {           $_session['message'] = "email cannot blank";      }else{         $query = "insert email_tbl (email, date)               values('$email', now())";             $insertemail = run_mysql_query($query);       if(run_mysql_query($query))     {         $_session['message'] .= "new record has been added correctly!";     }     else     {         $_session['message'] .= "failed add new interest";      }      }       header('location: email.php');     ?> 

here's delete.php file far:

<?php     require("new-connection.php");      session_start();       $query = "delete email_tbl             id={id} limit 1";             $deleteemail = run_mysql_query($query);       if(run_mysql_query($query))     {         $_session['message'] .= "record has been deleted correctly!";     }     else     {         $_session['message'] .= "failed delete record";      }        header('location: email.php');     ?> 

so when click delete link must delete button real time. idea?

modify delete.php retrieve url parameter:

<?php     require("new-connection.php");     session_start();      $id = $_get['id'];      $query = "delete email_tbl             id='$id' limit 1";             $deleteemail = run_mysql_query($query);       if($deleteemail)     {         $_session['message'] .= "record has been deleted correctly!";     }     else     {         $_session['message'] .= "failed delete record";      }      header('location: email.php'); ?> 

as add.php, using this:

$insertemail = run_mysql_query($query);      if(run_mysql_query($query)) 

you should change this:

$insertemail = run_mysql_query($query);       if($insertemail) 

what doing right executing query twice calling run_mysql_query twice. should fix it


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -