This topic is locked

Run Code on Child record

10/3/2011 4:42:24 AM
PHPRunner General questions
jclabuschagne author

PHPR 5.3 B7474
Goodday,
I have made an inline delete button for each record on the list page, and run an ajax query on it to load an external file to basically delete the record and refresh the page.
This works exactly as described for the parent records, but it doesn't work for any child records, so I have a few questions:
What code is run on child records if run inline, the same as if you opened it separately? The reason for asking being that the Delete button shows on the child records, but does nothing.
And before you ask, I have created another personalized external file for the child records, loaded with ajax, that is supposed to run if you click on the child records' Delete button, and I have also created a personalized ajax request for the child records because the id's of the parent Delete buttons is different from the Child Delete buttons. So where must I put the javascript(ajax) code to run it for the inline child records?
Here is my code:
Parent Delete Button(id is used to pass the record id):

$("input[type='button'][name='deletebut']").click(function(e){

$.ajax({ type: "POST",url: "http://splitseconds.co.za/ssdbforfans/deleterecord.php",data: "id="+$(this).attr('id'),success: function(msg){alert("");}

});

history.go(0);

});


Child Delete Button(id is used for the record id):

$("input[type='button'][name='deletebut2']").click(function(e){

$.ajax({ type: "POST",url: "http://splitseconds.co.za/ssdbforfans/deleterecord2.php",data: "id="+$(this).attr('id'),success: function(msg){alert("");}

});

history.go(0);

});


I have tried on both the Parent list javascript and the Child list javascript, but it doesn't work.
Or am I trying to find the problem at the wrong place.
Please help someone! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17867&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' /> this gets confusing...

C
cgphp 10/3/2011

Both codes go in the "Javascript OnLoad" event of the list page. Please, post the code of the deleterecord.php and deleterecord2.php.

jclabuschagne author 10/3/2011



Both codes go in the "Javascript OnLoad" event of the list page. Please, post the code of the deleterecord.php and deleterecord2.php.


Thanks Cristian,
deleterecord.php

<?php
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{
$dbc = mysqli_connect('splitseconds.co.za','USERNAME','PASSWORD','splits_db1')

or die('Error Occurred connecting to MySQL server'); // I replaced the username and password for security purposes
$query = "DELETE FROM FanComments WHERE CommentID='".$_POST['id']."'";
$result = mysqli_query($dbc,$query) or die('Error querying database');
}
?>


and deleterecord2.php

<?php

if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{
$dbc = mysqli_connect('splitseconds.co.za','USERNAME','PASSWORD','splits_db1')

or die('Error Occurred connecting to MySQL server');// I replaced the username and password for security purposes
$query = "DELETE FROM CommentsOnComments WHERE CommentsOnCommentsID='".$_POST['id']."'";
$result = mysqli_query($dbc,$query) or die('Error querying database');
}
?>
C
cgphp 10/3/2011

Remove the single quote around the $_POST['id'] variable. The correct versions are:

$query = "DELETE FROM FanComments WHERE CommentID=".$_POST['id'];



and

$query = "DELETE FROM CommentsOnComments WHERE CommentsOnCommentsID=".$_POST['id'];