Minklet Posted August 11, 2010 Share Posted August 11, 2010 I have altered this script to be able to delete a record from an upcoming gig table. Its fairly simple This is the ajax script: <script type="text/javascript"> jQuery(function() { jQuery(".delbutton").click(function(){ var member_id = jQuery("#member_id").val(); var element = jQuery(this); var d = new Date(); var del_id = element.attr("id"); var info = 'id=' + del_id + '&member_id=' + member_id + '&del=1&sht=' + d.getTime();'; if(confirm("Sure you want to delete this update? There is NO undo!")) { jQuery("#flash").show(); jQuery("#flash").fadeIn(400).html('<img src="http://tiggin.com/ajax-loader.gif"> <span class="loading">Loading Comment...</span>'); jQuery.ajax({ type: "POST", url: "insertgig.php", data: info, success: function(html){ jQuery("#display").html(html); jQuery("#flash").hide(); } }); } return false; }); }); </script> This is the php that builds and displays the table on the main page: <table width="90%"> <tr><td width="22%"><strong id="first">Date</strong></td><td width="23%"><strong>Event</strong></td><td width="23%"><strong>Venue</strong></td><td width="30"><strong>Event Link</strong></td></tr> <?php while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo '<tr><td width="22%">' . $row['date_of_gig'] . '</td><td width="23%">' . $row['promoter'] . '</td><td width="23%">' . $row['venue'] . '</td><td width="27%">'; if ($row['event_link'] != NULL) { echo '<a href="' . $row['event_link'] . '" title="Event Page" target="_blank" ><img style="border: none;" src="http://www.subverb.net/images/profile_facebookevent.jpg" alt="Facebook Icon" /></a>'; } echo '</td><td width="5%"><a href="#" id="' . $row["entry_id"] . '" class="delbutton"><img src="images/del.png" alt="delete"/></a> </td></tr>'; } echo '</table>'; ?> and this is the processing script, as you can see there is another ajax script that is used to add records by ajax, hence the if($_POST['del'] == 1) to check which query to execute. require_once('mysqli_connect.php'); if(isset($_SESSION['member_id'])) { if ($_POST['member_id'] == $_SESSION['member_id']) { if(isset($_POST['del']) && $_POST['del'] == 1) { $entry_id = $_POST['id']; $member_id = $_POST['member_id']; $query = "DELETE FROM upcoming_gigs WHERE entry_id = '$entry_id'"; $result = mysqli_query ($dbc, $query) or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); } else { $date = $_POST['date']; $venue = $_POST['venue']; $promoter = $_POST['promoter']; $eventlink = $_POST['eventlink']; $member_id = $_POST['member_id']; $query = "INSERT INTO upcoming_gigs (date_of_gig, venue, event_link, promoter, member_id) VALUES ('$date', '$venue', '$event', '$promoter', '$member_id')"; $result = mysqli_query ($dbc, $query) or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); } $result= mysqli_query($dbc, "SELECT * FROM upcoming_gigs WHERE member_id = '$member_id' ORDER BY date_of_gig asc") or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc));; $sht = date('U'); ?> <table width="90%"> <tr><td width="22%"><strong id="first">Date</strong></td><td width="23%"><strong>Event</strong></td><td width="23%"><strong>Venue</strong></td><td width="30"><strong>Event Link</strong></td></tr> <?php while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo '<tr><td width="22%">' . $row['date_of_gig'] . '</td><td width="23%">' . $row['promoter'] . '</td><td width="23%">' . $row['venue'] . '</td><td width="27%">'; if ($row['event_link'] != NULL) { echo '<a href="' . $row['event_link'] . '" title="Event Page" target="_blank" ><img style="border: none;" src="http://www.subverb.net/images/profile_facebookevent.jpg" alt="Facebook Icon" /></a>'; } echo '</td><td width="5%"><a href="#" id="' . $row["entry_id"] . '" class="delbutton"><img src="images/del.png" alt="delete"/></a> </td></tr>'; } echo '</table>'; } else { echo 'There was an error, or you do not have permission to edit this information. Please contact admin@subverb.net or start a help thread in the forum if this problem persists. Sorry for the inconvenience.'; } } else { echo 'There was an error, or you do not have permission to edit this information. Please contact admin@subverb.net or start a help thread in the forum if this problem persists. Sorry for the inconvenience.'; } ?> So anyway...once the delete script is executed once and the table is populated by the html kicked out by the processing page, clicking the delete link doesnt do anything. Nothing at all, firebug doesnt give me any errors, or any indication that anything is happening. I can't figure this out because the class names are exactly the same, in fact the source code of the page s exactly the same. Any reason why this is? Quote Link to comment Share on other sites More sharing options...
Minklet Posted August 11, 2010 Author Share Posted August 11, 2010 Ignore the '; at the end of the info declaration, that was a typo. Quote Link to comment Share on other sites More sharing options...
XeNoMoRpH1030 Posted August 11, 2010 Share Posted August 11, 2010 Seems like the old HTML is being replaced by the HTML generated by the PHP script. The thing is, you need to rerun that function that assigns the events to the delete button. Although it looks the same to you, those elements are new. I'd make your Javascript an actual function and so you can call it after the HTML is inserted onSuccess. Quote Link to comment Share on other sites More sharing options...
Minklet Posted August 11, 2010 Author Share Posted August 11, 2010 Thanks for the help, I'll give that a go Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.