Codeigniter is a MVC framework, which has its own functionality to insert a form data to mysql database table. Now by using ajax post method we will insert the codeigniter form data to mysql database table.
Now we will create a database table as branddetails, which looks as below.
After creating the table, now we will create a view to insert the
Form data to branddetails table.
Now store encoded text string to variable paramstr, now use jquery ajax post method to send form request using url.
Create branddetailsinsert method under dashboard controller in codeigniter. Let’s look into the code once to insert the form data from ajax post method.
In the above controller we are calling model class insertbranddetails() method to insert form data, as you know codeigniter uses model, view and controller architecture. Now let’s check model class methods in below code.
As you know when array is passed into codeigniter insert function
It will execute the method and inserts data into branddetails database table, and returns the stored variable $insertdet to controller method, finally controller function check’s weather the data inserted using if condition ,if its inserts return result as “successful” else return “not successful”.
This returned value is passed to ajax post method success function and displays alert message as successful.
Thanks for reading this article.