Forums

deleting database records from within a form

ramakunga 31 May, 2016
Hi Bob
I am trying to delete records from a database using the following proceedure but am not sure if it is the best way using chronoforms.

I basically have the data displaying using a custom code with the following html
<table width="700px" align="center" border="0">
<tr>
<td></td>
</tr>
<tr style="background-color:#DDD">
<th width="5%">ID</th>
<th width="12%">Date</th>
<th width="7%">Start Time</th>
<th width="7%">Finish Time</th>
<th width="7%">Meal Start</th>
<th width="10%">Meal Finish</th>
<th width="4%">Hours</th>
<th width="7%">Site</th>
<th width="33%">Remarks</th>
<th width="10%"></th>
</tr>
{repeater:extra}
   <tr>
		<td><?php echo  '{id}'; ?></td>
		<td><?php echo  '{Date_OT}'; ?></td>
		<td><?php echo '{StartTime_OT}'; ?></td>
		<td><?php echo '{FinishTime_OT}'; ?></td>
		<td><?php echo '{MealStart_OT}'; ?></td>
		<td><?php echo '{MealFinish_OT}'; ?></td>
		<td style="color: red"><?php echo '{Hours_OT}'; ?></td>
		<td><?php echo '{Site_OT}'; ?></td>
		<td><?php echo '{Remarks_OT}'; ?></td>
		<td class="DeleteRecord" id="deleteRecord"><a href=#>Delete</a></td>
	</tr>
   {/repeater}
</table>


I want the corresponding line to be deleted from the database when the delete link is clicked. to do this i was going to use the following jQuery

jQuery(document).ready(function(jQ) {
	jQ('.DeleteRecord').click(function(){  
		var del_recid = jQ(this).attr('id');  
		var parent = jQ(this).parent(); 
			jQ.post('delete.php', {id:del_recid},function(data){ 
				parent.slideUp('slow', function() {$(this).remove();
			}); 
			});
		});
	})


the delete.php is as follows:
<?php
$connection = mysql_connect('localhost', 'root', 'xxxx');
$db = mysql_select_db('c0aps1', $connection);
$id = $_POST['id'];
$safeid = mysql_real_escape_string($id);
$query = mysql_query("delete from jos_chronoengine_chronoforms_overtime where id=$safeid", $connection);
?>


The problem is where to place the delete.php to avoid getting the "unable to find URI error

so i guess my questions are
a) where do i put the delete.php file
b) or is there an easier way to do it in chronoforms using its in built functionality

I know chronoconnectivity would work its just i want to do this within the form

thanks in advance


The following jQuery to
GreyHead 31 May, 2016
Hi ramakunga,

I haven't read your code in detail but the way I would make an Ajax call from a form is to add a new form event and call that - the form event can then contain a Custom Code action that can use all of the Joomla! and ChronoForms methods if needed.

Bob
This topic is locked and no more replies can be posted.