PHP to MySql Database connection in WAMP Server [How to] - Helpwalaa - Free IT Updates & Opportunities

New Updates

PHP to MySql Database connection in WAMP Server [How to]

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: ApacheMySQL and one of PHPPerl 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.

Most Popular