Hello-
Now that I am able to get some more advanced things done with Chronoforms I am really excited to create some great form apps.
i made a form that lets the user recall a record from the table, edit it, and save it. Everything works.
I want to add the functionality to delete the record instead of saving it.
I created a checkbox on the form for the user to check if they want to delete the record.
I setup an event switcher and made sure it worked for updating the selected record (by event_id key).
So now I am trying to figure out how to execute a php/mysql command in custom code that would DELETE the record with ID of event_id.
Any suggestions?
Now that I am able to get some more advanced things done with Chronoforms I am really excited to create some great form apps.
i made a form that lets the user recall a record from the table, edit it, and save it. Everything works.
I want to add the functionality to delete the record instead of saving it.
I created a checkbox on the form for the user to check if they want to delete the record.
I setup an event switcher and made sure it worked for updating the selected record (by event_id key).
So now I am trying to figure out how to execute a php/mysql command in custom code that would DELETE the record with ID of event_id.
Any suggestions?
I guess the sql command would be something like:
$sql = "DELETE FROM events WHERE id='$event_id';
WOuld that work? How do I make chronoforms execute that in custom code?
$sql = "DELETE FROM events WHERE id='$event_id';
WOuld that work? How do I make chronoforms execute that in custom code?
oops i think i made a typo. Shouldn't it be:
$sql = "DELETE FROM events WHERE event_id='$event_id';
Hi Cyborprime,
BUT I would usually have a status column and set that to 'deleted' rather than actually delete the record as there is no easy way back from the deletion.
Bob
<?php
$db = \JFactory::getDBO();
$query = "
DELETE
FROM `#__table_name`
WHERE `id` = '{$form->data['event_id']}' ;
";
$db->setQuery($query);
$db->execute();
?>
BUT I would usually have a status column and set that to 'deleted' rather than actually delete the record as there is no easy way back from the deletion.
Bob
something like this?
I'm not sure how to trigger the query in custom code.
ow! my brain hurts! Thanks for indulging a noob,
<?php
$query = 'DELETE FROM `events` WHERE event_id = '$event_id';
$result = mysql_query($query,$link);
?>
I'm not sure how to trigger the query in custom code.
ow! my brain hurts! Thanks for indulging a noob,
oh - ok, I tried this, but it didnt work:
I changed your code from 'id' = to 'event_id' =
SHould I leave that alone as 'id'= ?
<?php
$db = \JFactory::getDBO();
$query = "
DELETE
FROM `events`
WHERE `event_id` = '{$form->data['event_id']}' ;
";
$db->setQuery($query);
$db->execute();
?>
I changed your code from 'id' = to 'event_id' =
SHould I leave that alone as 'id'= ?
duh - gotta take out the quotes i think.. brb
arrg! I have no idea what I'm doing or doing wrong here.
<?php
$db = \JFactory::getDBO();
$query = "
DELETE
FROM events
WHERE event_id = '{$form->data['event_id']}'
";
$db->setQuery($query);
$db->execute();
?>
i've tried all different combinations and none worked.
So with my example of:
table: events
key of current record: event_id
Should the code be:
im not having any luck
So with my example of:
table: events
key of current record: event_id
Should the code be:
<?php
$db =& JFactory::getDBO();
$query = "
DELETE FROM `events`
WHERE `event_id` = '{$form->data['event_id']}' ;
";
$db->setQuery($query);
$db->query();
?>
im not having any luck
oh sorry- looks like the switch for calling the delete event isnt working right, so the code you sent isnt getting called.
I'll troubleshoot this further and report back. Sorry - my bad.
I'll troubleshoot this further and report back. Sorry - my bad.
ok i took out that code and put in a display message that shows the switch *is* working.
I'm going to put the code you send in a custom code box and see what happens.
I'm going to put the code you send in a custom code box and see what happens.
ok no matter what I do i get error 114 - what does that mean?
I'm using an external database if that matters?
ok - I see by the error messages that it is looking in the joomla database instead of my external database.
so I figured it out - you have to use the joomla database connectors in your php script to link into and manipulate the external database otherwise you are hooking into the joonla database.
so I figured it out - you have to use the joomla database connectors in your php script to link into and manipulate the external database otherwise you are hooking into the joonla database.
Here's the solution:
<?php
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'mysql.database.name'; // Database host name
$option['user'] = 'my_database_user'; // User for database authentication
$option['password'] = 'my_password'; // Password for database authentication
$option['database'] = 'my_calendar'; // Database name
$db = JDatabaseDriver::getInstance( $option );
$query = "DELETE FROM `events` WHERE `event_id` = '{$form->data['event_id']}';
";
$db->setQuery($query);
$db->execute();
?>
This topic is locked and no more replies can be posted.