Wednesday, February 20, 2013

PHP to MySql Database connection in WAMP Server

WAMP is an acronym formed from the initials of the operating system Microsoft Windows and the principal components of the package: Apache, MySQL and one of PHP, Perl or Python. Apache is a web server. MySQL is an open-source database. PHP, Perl and Python are scripting languages that can manipulate information held in a database and generate web pages dynamically each time content is requested by a browser. Other programs may also be included in a package, such as phpMyAdmin which provides a graphical user interface for the MySQL database manager.


Setpwise  Procedure to Create webpage ,Connect to database  and Inserting data.

1-Install Wamp Server On PC. You can Get Installation tutorial on any website.

2- Now Start the Wamp Server and  do right click and click on phpmyadmin .

PhphMyadmin page will open and clikc on New database and create new database with uyour name



Now Create new table name as info with two field name as first and last





remaing  field let it be empty.


We are done with database .Now Create Web page


3- Make Simple webpage with two textbox... First Name and Last Name

code of html page-

<html>
<head>
</head>
<body>
<h1>My First Php Web Page</h1>

<form action="insert.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
<input type="Submit">
</form>
</body>
</html>
Save this file as index.html


Step 2-  Make Php File Which Handle that request-

<?php
$database="jayesh"; //database name
$first=$_POST['first'];//this values comes from html file after submitting
$last=$_POST['last'];
    $con = mysql_connect("localhost","root" ,"");//for wamp 3rd feild is balnk
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("$database", $con);

$query = "INSERT INTO info (first,last)VALUES ('$first','$last')";
mysql_query($query);

echo "<script type='text/javascript'>\n";
echo "alert('you are Succesflly registered');\n";
echo "</script>";


mysql_close();
?>


save this file as insert.php.

3-Put this both file in single Folder and Put this folder in Wamp installation directory, inside  WWW folder

defalut path is =C:\wamp\www\


4- Now again  do right click and click on local host . Main Page of wampserver will open.

On bottom left of project you will find directory in which we store both file. Click on that folder

Our index.html page will open
It will  Look Like this--->





Now Enter the details and and Submit it. Message box will come that you successfully insert data in database , in that way you can try for delete and modify operation.

Keep Sharing and Comment if any Difficulty...

Share This!


74 comments:

  1. After inserting data into the form, it tells me successfully inserted but problem is now that how do i view the data I have inserted through the form in the databse..i am not seeing it. and how do i add more data into the database for example if i have a registration form, then also a complaint for and more..

    ReplyDelete
    Replies
    1. i get same successfully entered data but it doesnt shows up

      Delete
  2. thanks for the tutorial. it really helped. however after doing all this i choose to increase my tables to about 7 with a textarea object but it doesn't save anymore... thanks for the anticipated help

    ReplyDelete
  3. Thank you very much ............this code really made my day!!!!

    ReplyDelete
  4. hey i want to go to another page on succesfully login>>>>
    go to example.php

    ReplyDelete
  5. thnx...for d tutotial.... it really helps me a lot....

    ReplyDelete
  6. the message comes like this "\n"; echo "alert('you are Succesflly registered');\n"; echo ""; - "
    and i couldnt see the result

    ReplyDelete
  7. I have been searching the internet for the past nine hours. I was close to a pitiful death until I came here. You have helped me beyond what any person has helped me before. You have rescued me from the pit of desperation and frustration, and brought me back into the light of understanding. A toast to your good sir. May you have long days and pleasant nights for as long as you shall live. Thank you.

    ReplyDelete
  8. Thanks! That really helped me alot

    ReplyDelete
  9. photo tagging code with demo with database
    http://www.lessonwithdemo.com/205/ajax/photo-tagging-like-facebook-without-page-refresh-with-ajax-without-jquery.php/

    ReplyDelete
  10. http://axegahukar.blogspot.in/2014/08/how-to-connect-database-in-aspnet.html

    ReplyDelete
  11. can't access the code . when i click submit button appear for full code

    ReplyDelete
  12. i created a folder of the 2 files specifies inside folder www. but the files din't run.Plzz tell what is the problem

    ReplyDelete
  13. Salaaaam....! How can i see the data in database... help me....

    ReplyDelete
  14. I am getting this error. Please help

    ( ! ) Notice: Undefined index: first in C:\wamp\www\insert.php on line 10
    Call Stack
    # Time Memory Function Location
    1 0.0520 134144 {main}( ) ..\insert.php:0

    ( ! ) Notice: Undefined index: last in C:\wamp\www\insert.php on line 11
    Call Stack
    # Time Memory Function Location
    1 0.0520 134144 {main}( ) ..\insert.php:0

    ( ! ) Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\insert.php on line 17
    Call Stack
    # Time Memory Function Location
    1 0.0520 134144 {main}( ) ..\insert.php:0
    2 0.2130 141784 mysqli_select_db ( ) ..\insert.php:17

    ( ! ) Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\insert.php on line 19
    Call Stack
    # Time Memory Function Location
    1 0.0520 134144 {main}( ) ..\insert.php:0
    2 0.3540 141928 mysqli_query ( ) ..\insert.php:19

    ReplyDelete
  15. It is showing error message when i click on submit, it shows "Not Found

    The requested URL /insert.php was not found on this server."
    What to do???

    ReplyDelete
  16. I like your post about database ... How create Database connection in php using wamp server http://bit.ly/1NOelur

    ReplyDelete
  17. Thank you very much for your good tutorial.well understood.

    ReplyDelete
  18. Thank You Very Much I was trying for same of about 1 month but i finally found this here.Once again thank you

    ReplyDelete
  19. After submission of the form, it did not show in the database.. the reason been that there is little code missing here

    $query = "INSERT INTO info (first,last)VALUES ('$first','$last')";
    mysql_query($query);

    it suppose to be
    $query = "INSERT INTO info (first,last)VALUES ('$_POST[first]','$_POST[last]')";
    mysql_query($query);

    ReplyDelete
  20. 1 error
    Deprecated:MySQL_connect (); the MySQL extension is deprecated and will be removed in the future: use MySQL or pdi instead in path on line 10


    Plz anyone can fix this

    ReplyDelete
  21. 1 error
    Deprecated:MySQL_connect (); the MySQL extension is deprecated and will be removed in the future: use MySQL or pdi instead in path on line 10


    Plz anyone can fix this

    ReplyDelete
  22. ( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp2\www\insert.php on line 6

    how to solve this type of error

    ReplyDelete
  23. HOW DO I SEE THE DATA I HAVE INSERTED?

    ReplyDelete
  24. Ohhh thank God, I ve been struggling with this for 3hrs, well Thx,
    I ve another issue, I created users and each user has apassword, to my surprised, any user can use any password so long as da password is in da database, eg a user landus with password 111, en user temba with password 333, but user temba can login using password for landus, ???? How can I overcome this, thanks

    ReplyDelete
  25. It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us. Website Development Bangalore | Web Design Company Bangalore India

    ReplyDelete
  26. The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..Website Developers Bangalore | Website Designing Bangalore

    ReplyDelete
  27. Thanks for sharing this type of information. It's very helpful for everyone. Keep posting. php course in pune

    ReplyDelete
  28. It does display that you have successfully registered.
    However, it does not display the result. It gives the following error.

    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\insert.php on line 5

    Please help me out

    ReplyDelete
  29. Thnku vry much...successfully tested the code...vry hppy tday :)
    This code really made my day

    ReplyDelete
  30. Thnku vry much...successfully tested the code...vry hppy tday :)
    This code really made my day

    ReplyDelete
  31. excellent description thanks alot!!!

    ReplyDelete
  32. This comment has been removed by the author.

    ReplyDelete
  33. sir i follow the same step as u text in above lines but i hav this error:
    ( ! ) Fatal error: Uncaught Error: Call to undefined function mysql_connect() in F:\wamp\www\New folder\insert.php on line 5
    ( ! ) Error: Call to undefined function mysql_connect() in F:\wamp\www\New folder\insert.php on line 5

    plz help me to solve this..

    ReplyDelete
  34. waooo nice post regarding "PHP to MySql Database connection in WAMP Server"

    Thanks,

    Crude Oil Trading Tips | Mcx Tips Free Trial

    ReplyDelete
  35. Webtrackker technology is the best IT training institute in NCR. Webtrackker provide training on all latest technology such as Php training. Webtrackker is not only training institute but also it also provide best IT solution to his client. Webtrackker provide training by experienced and working in the industry on same technology.Webtrackker Technology C-67 Sector-63 Noida 8802820025

    Php training institute in indirapuram


    Php training institute in Noida


    Php training institute in Ghaziabad


    Php training institute in Vaishali


    Php training institute in Vasundhara


    Php training institute in Delhi South Ex

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. thank u...
    before taking database connection,
    type " use database_name;" in MySQL console..

    ReplyDelete
  38. Will try, hope its all we need...For best and cheap manual Seo services, Web designings. Must check Web Design Bangalore

    ReplyDelete
  39. Your blog is very helpful and informative indeed. Thank you for sharing. For more information visit our websitePHP training

    ReplyDelete
  40. I went through your website it was really informative do visit my blog

    ReplyDelete
  41. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online course hyderabad

    ReplyDelete
  42. That's wonderful stuff you've written up here. Been searching for it all around. Great blog
    Web developers in bangalore
    Website Design and Development Companies in Bangalore

    ReplyDelete
  43. Nice blog Content.It is very informative and helpful. Please share more content. Thanks.
    PHP Training in Gurgaon
    PHP Course in Gurgaon
    PHP Institute in Gurgaon

    ReplyDelete
  44. Really very informative and creative contents. This concept is a good way to enhance the knowledge.thanks for sharing. please

    keep it up.
    PHP Training in Gurgaon

    ReplyDelete
  45. Really your content is so informative. So please share some more content ..
    PHP course in Noida

    ReplyDelete
  46. You really touched few great points of interest which might plainly be considerable for many visitors. I admire you for making such a pleasant article accessible to us. Keep blogging.
    Website Design Agency | Website design company

    ReplyDelete
  47. Nice blog Content.It is very informative and helpful. Please share more content. Thanks.
    PHP Training in Gurgaon

    ReplyDelete
  48. Nice blog.Gained more information about php.Keep blogging.for further reference refer php training in coimbatore

    ReplyDelete
  49. Kudos! Nice article. Informative and simple. If video, was there, still more informative and understandable. I work for non-profit organization and information stated would assist me organization very well.
    Mobile App Development Company

    ReplyDelete
  50. much needed information for my project and it works successfully. Thank you!!!!!

    ReplyDelete

  51. I would like to say thank you for the amazing details and concepts you are sharing in this.The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! to read. I never stop myself to say something about it. You’re doing a great job. Keep it up...





    Microsoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune






    ReplyDelete
  52. The Original Forex Trading System: roboforex login Is The Original Forex Trading System. It Is 100% Automated And Provides An Easy-to-follow Trading System. You Get Access To Real-time Signals, Proven Methods, And A Money-back Guarantee.

    ReplyDelete
  53. It's a superb article you've written here. Your article provided me with some unique and useful knowledge. Many thanks for bringing this post to our attention. PHP Training in delhi

    ReplyDelete
  54. Nice post, As you all guys know php programming and PHP also have a collection of errors so i am specifing some errors below.
    composer detected issues in your platform

    ReplyDelete
  55. Thanks for the informative article. This is one of the best tips in my life. I have in quite some time. Nicely written and great info. I really cannot thank you enough for sharing. Taκе a look at mу ωeb site Free Credit Card Number

    ReplyDelete
  56. cPanel License is a popular web hosting control panel that simplifies the process of website and server management.

    ReplyDelete