View Full Version : jQuery Passing data via Jquery to delete data from a mysql database

12-02-2010, 02:41 PM
Hi I am trying to get data from selected checkboxes using jQuery $post and then getting the values using PHP to delete from a database. I also would like a confirmation dialog to see if the user wants to delete the events. I have looked at various methods on the web but I keep getting stuck. I know a bit about jQuery but not a lot about ajax. Any pointers will be appreciated.


<form name='delete_form' action='' method='post'>
<input type="checkbox" value="131" name="deleteCB[]" class="cb" />
<input type="checkbox" value="32" name="deleteCB[]" class="cb" />
<input type="checkbox" value="129" name="deleteCB[]" class="cb" />
<input type='submit' id='deleteBtn' value='Delete' name='DeleteBtn' />

lit.js Not sure if this is correct

$("#deleteBtn").click(function() {
var confirmation = confirm("Are You Sure You Want to Delete These Events?")
if(confirmation == true)
$.post('process.php', { deleteCB: $(this).attr('value') },
alert('Items were successfully deleted.')});

return false;



$query_delete = "DELETE FROM events WHERE id='$value'";

Thanks in advance

12-02-2010, 06:26 PM
You might find this page (http://jetlogs.org/2007/06/17/jquery-tutorial-passing-input-arrays/) useful.

Also: validate your PHP input. What if some malicious person POSTed "' OR 1=1--" ?

12-03-2010, 08:43 PM
Thanks that site gave me some good pointers. I have included validation in my script I just didn't add it to my thread.

12-05-2010, 05:18 PM
I have a similiar use for this however my situation is that I have a listing of entries with checkboxes with their IDs attached to them in the coding but I have a dropdown with edit and delete and then a submit button next to it what kind of change would i make bases on the user's choice.

Both of these code blocks are from the same page.

<div class="listActions">
<form action="" method="post">
<label for="actionSelect">With selected items: </label>
<select class="select" name="actionSelect" id="actionSelect">
<option id="1">Edit</option>
<option id="2">Delete</option>
<button class="button small-button"><strong>Apply</strong></button>

while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
echo '
<td><input type=checkbox class=checkbox value="' . $row['id'] . '" /></td>
<td>' . $row['divisionname'] . '</td>
<td>' . $row['name'] . '</td>
<td class=last>' . $row['datecreated'] . '</td>