× Form Help

Delete an entry from a database table

  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 236
  • Karma: 1
  • Thank you received: 26

Eddy.vh created the topic: Delete an entry from a database table

Hello.

I would like to know if, using a BreezingForms form, it is possible to delete an entry from a database table.

Ex. I have a line with a subscriber email:
If I activate a checkbox, can I delete the corresponding line with this query?
I need to manage the unsubscribing and deletion of subscribers for an extension that does not offer automation.

Does this query seem correct?

$subscriberEmail = ff_getSubmit('email');
$db->setQuery("DELETE from #__my_table WHERE email = ' $id_subscriberEmail'");

I was able to manage the registration using BreezingForms and the validation with BF + Integrator. Now, i need to manage the unsubscribing and deletion of subscribers for an extension that does not offer automation.

Thank you for your help.
#237503
  • Posts: 2553
  • Karma: 87
  • Thank you received: 343

mihaela replied the topic: Delete an entry from a database table

Hello,

Your query seems fine.

If you wish to have a checkbox where the user decides whether to delete the account, then the code would go something like this:
if ( ff_getSubmit('checkboxName') == "checked") {
    $subscriberEmail = ff_getSubmit('email');
    $db->setQuery("DELETE from #__my_table WHERE email = ' 
    $id_subscriberEmail'");
    $db->execute();
}

That would delete a row in database table #__my_table where email corresponds to the email which was just entered in the form.

Let me know whether this is working as you wanted.

Regards,

Mihaela
#237542
The following user(s) said Thank You: Eddy.vh
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 236
  • Karma: 1
  • Thank you received: 26

Eddy.vh replied the topic: Delete an entry from a database table

Mihaela,

You're fantastic, I've been looking for a solution for days and it seems I forgot to start the execution.
$db->execute();

I thank you and wish you an excellent weekend.
#237544
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 236
  • Karma: 1
  • Thank you received: 26

Eddy.vh replied the topic: Delete an entry from a database table

Mihaela

One more question.
If I have to execute several queries, I suppose it is necessary to run $db->execute(); after each of them?
#237545
  • Posts: 2553
  • Karma: 87
  • Thank you received: 343

mihaela replied the topic: Delete an entry from a database table

Hi Eddy,

I'm really glad I've helped and that this is now working for you. :)

I thought that $db->execute(); might be what you have been missing.

As for the "If I have to execute several queries, I suppose it is necessary to run $db->execute(); after each of them?", it depends on what kind of query you are writing.

Here is an example:
$db = JFactory::getDbo(); // Get Database Object
$db->setQuery('SELECT ...'); 
$result = $db->loadResult();

$db2 = JFactory::getDbo(); // Get Database Object
$db2->setQuery('DELETE ...'); 
$result = $db2->execute();
So, if you are fetching a value with, for example, SELECT query, then the database query will be run with functions like: loadResult(), loadObjectList(), loadAssoc() etc.

On the other hand, if you are writing a DELETE query, since no value is returned, it is necessary to have execute() function to run the query.

You can read more about setQuery function here docs.joomla.org/Selecting_data_using_JDatabase .

I hope this helps.

Regards,

Mihaela
#237555
The following user(s) said Thank You: Eddy.vh
  • Eddy.vh
  • Eddy.vh's Avatar Topic Author
  • Away
  • Gold Boarder
  • Gold Boarder
  • Posts: 236
  • Karma: 1
  • Thank you received: 26

Eddy.vh replied the topic: Delete an entry from a database table

Hello Mihaela.

This weekend, I was able to do some tests and complete the project.
Thanks for your help, I was able to understand many things and especially how to read and write to a database, modify data in a database, and delete data that was no longer needed.

I finally rewrote the scripts to get a form capable of registering a subscriber, a subscription confirmation form activating the subscriber and placing him in a subscriber group.
The unsubscribe form deletes the subscriber and removes him from the group. And all this without having to use Integrator.

Thank you for your good tips.
#237559
Moderators: ForumSupporttomeperica
Time to create page: 0.088 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here