How to delete db record

jhainsworth 24 Feb, 2012
I have read all the post on the forum and just can't figure this out.

I know I am missing something simple. I have a db multi-record wizard form that correctly calls a custom form called DeleteMember and passes cf_id as a request item.

The html code in my custom form is:

<?php
    $cf_id = JRequest::getInt('cf_id', '', 'get');
    echo $cf_id;
    $db =& JFactory::getDBO();
    $query = "
      DELETE
        FROM `cbc_chronoforms_data_churchmembers`
        WHERE `cf_id` = '{$cf_id}' ;
    ";
    $db->setQuery($query);
    $db->query();
    $mainframe =& JFactory::getApplication();
    $mainframe->redirect('index.php?option=com_chronoforms&chronoforms/?chronoform=ChurchFamilyMemberList&fid={$fid}');
?>


All that happens is the a DeleteMember display a blank form.

Any help is greatly appreciated.
GreyHead 24 Feb, 2012
Hi jhainsworth,

That looks Ok apart from the redirect URL which has some junk left in it.
index.php?option=com_chronoforms&chronoforms/?chronoform=ChurchFamilyMemberList&fid={$fid}
should presumably be
index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid={$fid}
though as $fid isn't defined here so it will presumably display an empty form with the url
index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid=


Bob
jhainsworth 25 Feb, 2012
Bob,

The code never seems to execute.

It doesn't delete the record and it stays on the DeleteMember page rather than redirecting.

I had taken out the fid code, but it didn't work with the code in it either.

I will put the fid code back and try it again.

Thanks
jhainsworth 25 Feb, 2012
Bob,

Here is the full code with the fid in it:
<?php
    $fid = JRequest::getInt('fid', '', 'get');
    $cf_id = JRequest::getInt('cf_id', '', 'get');
    $db =& JFactory::getDBO();
    $query = "
      DELETE
        FROM `cbc_chronoforms_data_churchmembers`
        WHERE `cf_id` = '{$cf_id}' ;
    ";
    echo $query
    $db->setQuery($query);
    $db->query();
    $mainframe =& JFactory::getApplication();
    $mainframe->redirect('index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid={$fid}');
?>


It doesn't execute the redirect and it doesn't even do the echo of the query string.

Not sure what I am missing.
GreyHead 25 Feb, 2012
Hi jhainsworth,

Try setting Error Reporting to Maximum temporarilty to see if there is a PHP error - though the code looks Ok to me except for this line
$mainframe->redirect('index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid={$fid}');
which needs double quotes to get the {$fid} to work.

Do you have a Show HTML action for this form?

Bob
jhainsworth 25 Feb, 2012
Hi Bob,

I don't have a show HTML action. This is my first custom form and I didn't know I could do wizard actions in a custom form.

How do I do that?
GreyHead 25 Feb, 2012
Hi jhainsworth,

Save & Close the form then click the Wizard Edit link and you have all the usual tabs except that the preview window is blocked.

Bob
jhainsworth 25 Feb, 2012
OK, I added a show html action to the onload event, but nothing changed. My code still doesn't get executed.
jhainsworth 25 Feb, 2012
Hi Bob,

I know I must be missing sometihing simple.

If I comment out the last 4 lines of code, that actually work with the db and mainframe objects then it does display the delete statement.

<?php
    $fid = JRequest::getInt('fid', '', 'get');
    $cf_id = JRequest::getInt('cf_id', '', 'get');
    $db =& JFactory::getDBO();
    $query = "
      DELETE
        FROM `cbc_chronoforms_data_churchmembers`
        WHERE `cf_id` = '{$cf_id}' ;
    ";
    echo $query
#    $db->setQuery($query);
#    $db->query();
#    $mainframe =& JFactory::getApplication();
#    $mainframe->redirect('index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid={$fid}');
?>


What could I be missing?
jhainsworth 25 Feb, 2012
I have finally got the delete to work.

After putting in the show html action and doing some debuging, I found that I had a line that didn't have a ";" at the end of it.

correct code is

<?php
    $fid = JRequest::getInt('fid', '', 'get');
    $cf_id = JRequest::getInt('cf_id', '', 'get');
    $db =& JFactory::getDBO();
    $query = "
      DELETE
        FROM `cbc_chronoforms_data_churchmembers`
        WHERE `cf_id` = '{$cf_id}' ;
    ";
    $db->setQuery($query);
    $db->query();
    $mainframe =& JFactory::getApplication();
    $mainframe->redirect("index.php?option=com_chronoforms&chronoform=ChurchFamilyMemberList&fid={$fid}");
?>


Thanks Bob for all your patient support.
GreyHead 26 Feb, 2012
Hi jhainsworth,

Great - good to see you got it working. Bugs like a missing ; are often the easiest to make and the hardest to track down.

Bob
jmarian1 17 Sep, 2012
Hi. I have the same problem using the delete query but Chrono Connectivity works like a charm.
This topic is locked and no more replies can be posted.