News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Execute code if 'db_insert' unsuccessful?

Started by Morsyl, February 18, 2013, 11:51:27 PM

Previous topic - Next topic

Morsyl

Hi,
I'm currently working on a form which collects input, stores it a database, and creates a topic for user feedback.

I was wondering whether it's possible to automatically delete the created topic (or execute any code really) if the 'db_insert' is unnsuccessful and avoid (or delay) the fatal error.


Something along these lines...


//Create topic stuff
//
if(createTopic == successful)
{
//insert data into database, including topic & message IDs
        //
if(insert == unnsuccessful)
{
//delete topic??
}
}


Thanks in advance :)

Arantor

Better question is under what circumstances would it be unsuccessful?

The only times it would ever be unsuccessful from my perspective is if there's already something grossly wrong with the system anyway.
Holder of controversial views, all of which my own.


Morsyl

Hmmm... that's a good question. Thanks  :)

I suppose the only thing that can go wrong is hosting/database malfunction. Inputs are strings or integers and they're all sanitised and cast properly.

I dunno, I'm probably just being too worried about error catching.

Thanks  ;)

Arantor

Exactly it - if there's a DB malfunction, there's nothing you can do about it anyway.
Holder of controversial views, all of which my own.


Advertisement: