Forums

PHP

This topic is locked

deleting records into two tables... pls help... thanks

Posted 21 Jun 2012 08:34:50
1
has voted
21 Jun 2012 08:34:50 Li Bunton posted:
Hi! I'm working on a 'Record Management System' for my thesis. I had a problem with deleting two records into two tables. When I delete one record in 'new_dockets', the duplicate in 'all_dockets' should be delete also.

SQL:

TABLE1: 'all_dockets'

id, classification, tcc_number, tcc_date, company_name, status_request, time_date_created

TABLE2: 'new_dockets'

id, classification, tcc_number, tcc_date, time_date_created



here's the code:

new_docket.php
<div align="center" class="formarea">
			
		<div>
		<br />
				<font face="Verdana" style="font-size: 36px; font-style:normal; color: #333333"><b>NEW DOCKET</b></font>
				<br />
				<font face="Verdana" style="font-size: 22px; font-style:normal; color: #000000">DOCKET INFORMATION</font>
				<br /><br />
	
<?php

        include('db_connect.php');
        
        $per_page = 10;
        
        $result = mysql_query("SELECT * FROM new_dockets ORDER BY time_date_save DESC");
        $total_results = mysql_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];
                
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                $start = 0;
                $end = $per_page; 
        }
        
        
        echo "<p><a href='viewallnewdockets.php'>View First</a> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='viewallnewdockets.php?page=$i'>$i</a> ";
        }
        echo "</p>";
                

        echo "<table border='1' cellpadding='10'>";
        echo "<tr><th>Delete</th> <th>Date Created</th> <th>TCC Number</th> <th>Company Name</th> <th>Index Number</th> <th>View</th> <th>Edit</th> </tr>";

        for ($i = $start; $i < $end; $i++)
        {

                if ($i == $total_results) { break; }
        

                echo "<tr>";
				echo '<td align="center"><a href="deleteNewDocket.php?id=' . mysql_result($result, $i, 'id') . '" onclick="return confirm(\'Are you sure you want to delete this?\');"><img src="images/x.jpg" /></a></td>';
                echo '<td>' . mysql_result($result, $i, 'time_date_save') . '</td>';
                echo '<td><b>' . mysql_result($result, $i, 'tcc_number') . '</b></td>';
				echo '<td>' . mysql_result($result, $i, 'company_name') . '</td>';
				echo '<td><b>' . mysql_result($result, $i, 'cabinet_row');
				echo '<font>-</font>' . mysql_result($result, $i, 'cabinet_name');
				echo '<font>-</font>' . mysql_result($result, $i, 'cabinet_layer') . '</b></td>';
				echo '<td align="center"><a href="viewnewdocket.php?id=' . mysql_result($result, $i, 'id') . '" ><img src="images/view1.jpg" /><a></td>';
                echo '<td align="center"><a href="editnewdocket.php?id=' . mysql_result($result, $i, 'id') . '" ><img src="images/edit.jpg" /></a></td>';
                echo "</tr>"; 
        }
        
		echo "</table>"; 
                
?>
			<p align="center"><a href="reports.php"><img src="images/back2.jpg"/></a></p>
		</div>
	</div>



delete.php

<?php

	include('db_connect.php');
 
	if (isset($_GET['id']) && is_numeric($_GET['id']))
	{
 		$id = $_GET['id'];
 
 		$result = mysql_query("DELETE FROM new_dockets WHERE id = $id");
 
 		header("Location: new_docket.php");
 	}
 
 	else
 	{
 		header("Location: new_docket.php");
 	}

?>



they have different ID's...
thanks....

Reply to this topic