<?php require_once('connection.php'); ?>
<?php
in
/* now to display the data from the database which we inserted in above form */
/* we make the query to select data from the table EMP */
$display = "select * from tb_cform";
$result = mysql_query($display, $connection) or die(mysql_error()); /* the query is executed and result of the query is stored in variable $result */
if ($result == FALSE) {
    die(mysql_error()); /* displays error */
} ?>
<h1 align="center"> Displaying Records in Table </h1>
<form method="get" action="" id="deleteform" >
    <table width="245" border="1" align="center">
        <tr>
            <td width="51">
                <input type="submit" name="delete" id="button" value="delete" onclick="document.getElementById('deleteform').action = 'delete.php';document.getElementById('deleteform').submit();"/> <!--- here on clicking the button the form is submitted and action is set to delete.php Here we have used javaScript document refers to this whole page and now we can access any tag that has its id with help of getElementById() method and after the we specify the operation we want to perform in this case action and submit. --->
            </td>
            <td width="50">id</td>
            <td width="55">name</td>
            <td width="47">lastname</td>
        </tr>
 <?php
 while ($rows = mysql_fetch_array($result))
        { /* here we make use of the while loop which fetch the data from the $result int array form and stores in $row now we can display each field from the table with $row[‘field_name’] as below */
     ?>
                <tr>
                    <td>
                        <input type="checkbox" name="empids[]" value="<?php echo $rows['id']; ?>" /> <!--here with each checkbox we send the id of the record in the empids[] array --->
                    </td>
                    <td>
                        <?php echo $rows['id'] ?>
                    </td>
                        <td>
                            <?php echo $rows['lastname'] ?>
                        </td>
                        <td><?php echo $rows['name'] ?></td>
                            <?php } ?>
                </tr>
            </table>
        </form> ?>
    </body>
</html>
