Forums

Delete a record using Chronoforms

mapme 11 May, 2013
Hi,

I am hoping to add an action in Chronoforms where users can delete a record by submitting the form.
I've tried this with cUrl, but isn't working for me.

I have set up a PHP file that can be run, and the parameter is passed to determine the record that is deleted. Records are from an original Chronoform, and cf_uid is the unique value. The PHP is as follows, and "mem_id" is the parameter that is passed in the URL address:

<?php
$con=mysqli_connect("localhost","username","password","databasename");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="DELETE FROM calert_Members WHERE cf_uid = '$_GET[mem_id]'";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }

mysqli_close($con);
?>


When the web address is manually loaded with a valid cf_uid (index.php?mem_id=1234567890etc) from Firefox the record is deleted.

However when I attempt this using cUrl in Chronoforms it appears that the parameter is not passed. Well, if it is, then something else is up as the record is not deleted!

I've attached a copy of my cUrl action settings along with the debugger results when the form is published. The original website name has been changed...

Can you please let me know if I am doing something really wrong here... is cUrl the correct action to use, or is there another easier alternative?

Many thanks,

Brendan
GreyHead 12 May, 2013
HI mapme,

Why do you need an external file and cURL to do this? If it is happening when a form is submitted then you can just add the PHP+MySQL in a Custom Code action in the On Submit event. That would be something like this:
<?php
$db =& JFactory::getDBO();
$query = "
  DELETE FROM `#__calert_Members`
    WHERE `cf_uid` = '{$form->data['mem_id']}' ;
";
$db->setQuery($query);
$db->query();
?>

Bob
mapme 12 May, 2013
Thanks Bob,

Good question - there are 3 applications that are trying to delete records from that table so the two non-Joomla apps were interacting with that page... thought it was a good option to go with the same using cUrl.

However, you fixed my problem with the sample code you provided... the following code was my problem:
{$form->data['mem_id']}

Thanks for providing that fix!

All working perfectly now.
This topic is locked and no more replies can be posted.