Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:56:03+00:00 2026-06-07T01:56:03+00:00

I am new to CI and PHP too. I have a form that which

  • 0

I am new to CI and PHP too.

I have a form that which add a company and its contacts to the server including file upload .

i need all things on one button click.

so

function create_company()
{

 $insert = $this->database->insert();

 return $insert["insertID"]; //returns the inserted ID

}

function file_upload()
{

//upload files if there are some file input selected

return $array_of_uploaded_files;
}

function insert_contacts($company_id,$contacts_array)
{
//return true if everything success

}

My problems are

  1. First Company insertion is success,but failed to add its contacts,then i need to delete the current inserted item
  2. If insert_contact failed i need to delete the uploaded files

So is there any way to roll back actions if one or more of its dependency failed ?

I know transactions in Codeignitor ,but how can i use it [with multiple function scope] ?

What about file upload ?

Please note that i am asking this question because i am new to php , what i can do is that create so many functions and call it on appropriate situations.

I just want to know that how can i improve or simplify my codes…

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:56:04+00:00Added an answer on June 7, 2026 at 1:56 am

    Why not use transactions?

    http://ellislab.com/codeigniter/user-guide/database/transactions.html

    So something like:

    $this->db->trans_start();
    // your database queries
    $this->db->trans_end();
    

    Check if there’s any error with the transaction by:

    $this->db->trans_status();    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to MYSQL and have a problem. Its related to php too
I upload a file to a server by filling out a form. The file
I am trying to use a PHP form (new.php) to update 2 MySQL tables
We are in the startup build phase of a new PHP webapp that will
New to PHP and MySQL, have heard amazing things about this website from Leo
Am new to php... I have been battling on my dynamic checkboxes in such
hi i am new to css and php too i tried to use it
I have a form which allows users to comment on a page, however they
I'm very new to PHP so far and have been trying to learn it.
I am new to PHP, but have a decent grasp of things (have not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.