This tutorial helps to developer when developer want to insert data into database (MySQL) with PHP MVC. MVC contains on an Model, View and Controller. In a Model programmer write the code related to Database or business logic. In View create the layout or forms and using the Controller Model return the data on a View.
To insert into mysql php mvc we follow the few simple steps.
Now enter the required field data and press Save button. If the record inserted then the "Insert Data Successfully" message will display as shown in bellow mention screen shot. and if the data will not inserted then the "Error...! Not Inserted." message will display.
To insert into mysql php mvc we follow the few simple steps.
Step 1:
Create the 3 folders with the name Model,View and Controller respectively. Also Create a index.php file.
Folders and file which is used |
In Controller folder create Controller.php.
In Model folder create Model.php.
In View folder create view.php.
Step 2:
in the above mention index.php file write the following code:
<?php
include_once("Controller/Controller.php");
$Controller = new Controller();
$Controller->show();
?>
Step 3:
Now in the Controller folder create a file with name "Controller.php" and write the bellow mentioned code.
<?php
include_once("Model/Model.php");
Class Controller{
public $model;
public function Controller()
{
$this->model=new Model();
}
public function show()
{
$result = $this->model->insert_data();
include 'View/view.php';
}
}
?>
Step 4:
Create a "Model.php" file inside the Model folder and write the code like this.
<?php
Class Model{
public function Model()
{
$con = mysql_connect("localhost","root","") or die('Not connected to Database<br>' . mysql_error());
mysql_select_db("mvc_db",$con) or die('Not Select Database' . mysql_error());
}
public function insert_data()
{
if (isset($_POST['name']) && isset($_POST['age']) && isset($_POST['name'])) {
$name = $_POST['name'];
$age = $_POST['age'];
$city = $_POST['city'];
$qry = "insert into table1 (name,age,city) values('$name',$age,'$city')";
$result = mysql_query($qry);
if ($result) {
return "Insert Data Successfully.";
}
else
{
return "Error...! Not Inserted.";
}
}
else
{
return "";
}
}
}
?>
Step 5:
At last create the "view.php" file in View folder and write the following code. It's simple html base form.
<!DOCTYPE html>
<html>
<head>
<title>Insert Data in MySQL using PHP MVC</title>
</head>
<body>
<?php
echo $result;
?>
<form action="" method="POST">
<p>
<label>Name</label>
<input id="name" value="" name="name" type="text" required="required" /><br />
</p>
<p>
<label>Age</label>
<input id="age" name="age" type="text" required="required" /><br />
</p>
<p>
<label>City</label>
<input id="city" value="" name="city" type="text" required="required" /><br>
</p>
<br />
<p>
<button type="submit" class="green big" name="submit"><span>Save</span></button> <button type="reset" class="grey big"><span>Cancle</span></button>
</p>
</form>
</body>
</html>
output:
After complete all these five steps open the "index.php" file on browser. Form will display like this:
Insertion Form |
After data inserted successfully |
plz give the discription with detail then it will be suberb
ReplyDeleteStep by step explanation is nice to understand.But i have learned html coding but php is something different so i need a detailed informative to learn more.
ReplyDeletePhp Training in Chennai
Hi to every one, the contents present at this site are
ReplyDeleteactually remarkable for people experience, well, keep up the good work fellows.
php training in chennai
this post is very imformative for developer who wants more information regarding the programming language.thanks for sharing this post.
ReplyDeletephp training in nagpur
Awesome data for me....thanks for sharing the instructive post...am took in some data about PHP. PHP Training Institute in Ahmedabad , PHP classes in Ahmedabad
ReplyDeleteVery good PHP tutorial for learning php. Thanks.
ReplyDeleteSoftware Company in Dehradun
I simply want to give you a huge thumbs up for the great info you have got here on this post.
ReplyDeleteOracle training in chennai
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteDevops Training in Chennai
Devops Training in Bangalore
AWS Training in chennai
AWS Training in bangalore
Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!
ReplyDeletepython training in tambaram
python training in chennai
python training in annanagar
python training in chennai
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
ReplyDeleteBlueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
ReplyDeleteData Science training in kalyan nagar | Data Science training in OMR
Data Science training in chennai | Data science training in velachery
Data science online training | Data science training in jaya nagar
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteData Science course in kalyan nagar | Data Science course in OMR
Data Science course in chennai | Data science course in velachery
Data science online course | Data science course in jaya nagar
Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
ReplyDeletejava training in chennai
java training in marathahalli | java training in btm layout
This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here
ReplyDeleteangularjs Training in chennai
angularjs-Training in pune
angularjs-Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
I recently came across your blog and have been reading along. I thought I would leave my first comment.
ReplyDeleteJava training in Bangalore | Java training in Btm layout
Java training in Bangalore | Java training in Marathahalli
Java training in Bangalore | Java training in Btm layout
Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
ReplyDeletepython course in pune
python course in chennai
python course in Bangalore
I was looking for this certain information for a long time. Thank you and good luck.
ReplyDeleteangularjs-Training in pune
angularjs-Training in chennai
angularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleteData Science training in Chennai | Data Science Training Institute in Chennai
Data science training in Bangalore | Data Science Training institute in Bangalore
Data science training in pune | Data Science training institute in Pune
Data science online training | online Data Science certification Training-Gangboard
Data Science Interview questions and answers
Data Science Tutorial
information
ReplyDeleteinformation
ReplyDeleteThanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
rpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
ReplyDeleteThanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
rpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAWS Interview Questions And Answers | AWS Interviews Questions and Answers for Devops | AWS interview questions and answers for Sysops
AWS Interview questions and answers for freshers | AWS Interview Question for devops
AWS Training in Bangalore with placements | AWS Training in Bangalore cost
Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
ReplyDeletecontribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore | best selenium training in bangalore | advanced selenium training in bangalore | no.1 selenium training in bangalore
Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
ReplyDeleterpa training in bangalore
rpa training in pune
rpa online training
best rpa training in bangalore
It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
ReplyDeleteSelenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Selenium training in bangalore
This comment has been removed by the author.
ReplyDeleteExisting without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
ReplyDeletepython Online training in chennai
python Online training in bangalore
python interview question and answers
I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
ReplyDeleteData Science Training in Indira nagar
Data Science Training in btm layout
Data Science Training in Kalyan nagar
Data Science training in Indira nagar
Data science training in bangalore
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
ReplyDeleteAWS Training in pune
AWS Online Training
AWS Training in Bangalore
Great blog, I was searching this for a while. Do post more like this.
ReplyDeleteDevOps Training in Chennai
AWS Training in Chennai
Data Science Course in Chennai
ccna course in Chennai
Python Training in Chennai
R Programming Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai
Blue Prism Training in Chennai
Thanks For Sharing your Information The Information Shared Is Very Valuable Please Keep Updating Us Time Just Went On reading the article Data Science Online Training Hadoop Science Online Training AWS Online Training Python Online Training
ReplyDeleteI really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeleteTableau Training in Chennai
Tableau Training in Bangalore
Tableau Training in Bangalore
Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
ReplyDeleteJava Training in Electronic City
I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
ReplyDeleteData science Course Training in Chennai |Best Data Science Training Institute in Chennai
RPA Course Training in Chennai |Best RPA Training Institute in Chennai
AWS Course Training in Chennai |Best AWS Training Institute in Chennai
I Got Job in my dream company with decent 12 Lacks Per Annum Salary, I have learned this world most demanding course out there in the current IT Market from the Data Science Training in Pune Providers who helped me a lot to achieve my dreams comes true. Really worth trying.
ReplyDeleteThank you for Updating this Blog.The Blog is very Impressive and the content should be very unique and the concept are clearly explained by this Blog.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.. it was so good to read and useful to improve my knowledge as updated one, keep sharing more information…!!Data Science Training In Chennai
ReplyDeleteData Science Online Training In Chennai
Data Science Training In Bangalore
Data Science Training In Hyderabad
Data Science Training In Coimbatore
Data Science Training
Data Science Online Training
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI'm dazzled, I should say. Only sometimes do I go over a blog that is both educative and intriguing, and doubtlessly, you have nailed it. The issue is an issue that insufficient people are talking cleverly about. Presently i'm upbeat I unearthed this during my chase for something with respect to this. news updates
ReplyDeleteVery intersting content.Thanks for sharing.
ReplyDeleteSQL Course in Pune