{"id":2637,"date":"2018-10-05T20:59:51","date_gmt":"2018-10-05T15:29:51","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2637"},"modified":"2018-10-05T20:59:51","modified_gmt":"2018-10-05T15:29:51","slug":"insert-data-into-database-using-codeigniter","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/insert-data-into-database-using-codeigniter\/","title":{"rendered":"Insert data into database using codeigniter"},"content":{"rendered":"<p><strong>Insert data into database using codeigniter<\/strong><\/p>\n<p><strong>Date posted: 04-oct-2018<\/strong><\/p>\n<p>Please follow\u00a0 the steps to insert data into database using codeigniter<\/p>\n<p>Step 1: Create a new file under the path Application\/controllers\/Insert.php.Copy the below given code in your view.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;?php\r\nclass Insert extends CI_Controller \r\n{\r\n\tpublic function __construct()\r\n\t{\r\n\t\/\/call CodeIgniter's default Constructor\r\n\tparent::__construct();\r\n\t\r\n\t\/\/load database libray manually\r\n\t$this-&gt;load-&gt;database();\r\n\t\r\n\t\/\/load Model\r\n\t$this-&gt;load-&gt;model('Insert_Model');\r\n\t}\r\n \r\n\tpublic function savedata()\r\n\t{\r\n\t\t\/\/load registration view form\r\n\t\t$this-&gt;load-&gt;view('registration');\r\n\t\r\n\t\t\/\/Check submit button \r\n\t\tif($this-&gt;input-&gt;post('save'))\r\n\t\t{\r\n\t\t\/\/get form's data and store in local varable\r\n\t\t$n=$this-&gt;input-&gt;post('name');\r\n\t\t$e=$this-&gt;input-&gt;post('email');\r\n\t\t$m=$this-&gt;input-&gt;post('mobile');\r\n\t\t\r\n\/\/call saverecords method of Insert_Model and pass variables as parameter\r\n\t\t$this-&gt;Insert_Model-&gt;saverecords($n,$e,$m);\t\t\r\n\t\techo \"Records Saved Successfully\";\r\n\t\t}\r\n\t}\r\n}\r\n?&gt;<\/pre>\n<p>Step 2: Create a new file under the path Application\/views\/registration.php. Copy the below given code in your view.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Registration form&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n  &lt;form method=\"post\"&gt;\r\n    &lt;table width=\"600\" border=\"1\" cellspacing=\"5\" cellpadding=\"5\"&gt;\r\n  &lt;tr&gt;\r\n    &lt;td width=\"230\"&gt;Enter Your Name &lt;\/td&gt;\r\n    &lt;td width=\"329\"&gt;&lt;input type=\"text\" name=\"name\"\/&gt;&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n  &lt;tr&gt;\r\n    &lt;td&gt;Enter Your Email &lt;\/td&gt;\r\n    &lt;td&gt;&lt;input type=\"text\" name=\"email\"\/&gt;&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n  &lt;tr&gt;\r\n    &lt;td&gt;Enter Your Mobile &lt;\/td&gt;\r\n    &lt;td&gt;&lt;input type=\"text\" name=\"mobile\"\/&gt;&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n  &lt;tr&gt;\r\n    &lt;td colspan=\"2\" align=\"center\"&gt;&lt;input type=\"submit\" name=\"save\" value=\"Save Data\"\/&gt;&lt;\/td&gt;\r\n  &lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n  &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>Step 3: Create a new file under the path Application\/models\/Insert_Model.php. Copy the below given code in your model.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;?php\r\nclass Insert_Model extends CI_Model \r\n{\r\n  function saverecords($name,$email,$mobile)\r\n  {\r\n  $query=\"insert into users values('','$name','$email','$mobile')\";\r\n  $this-&gt;db-&gt;query($query);\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Insert data into database using codeigniter Date posted: 04-oct-2018 Please follow\u00a0 the steps to insert data into database using codeigniter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[341,179,273],"class_list":["post-2637","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-codeigniter","tag-mysql-2","tag-php","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-Gx","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2637"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2637\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}