Skip to main content

PHP to MySql Database connection in WAMP Server

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 your 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.

Comments

Popular posts from this blog

FB (Facebook ) Keyboard Short Cuts For - Google Crom , Firefox & Internet Explorer

FB (Facebook ) Keyboard Short Cuts For - Google Crom , Firefox & Internet Explorer Many Facebook users don't know about Fb keyboard short cuts keys , That's why I like to share here , Many users spends hours on fb and some time don't like to use mouse and touchpad that time use this trick , Its gives you more faster experience on fb .. Enjoy Facebook Short Cuts Keys For Google Chrome & Internet Explorer ( Note - No Need To Use + button , Only Push Alt key and 1 ) Alt + 1 = Facebook Home Page Alt + 2 = Profile Page Alt + 3 = Friend Request List Alt + 4 = Latest Messages List Alt + M = Create New Message Alt + 5 = Notification List Alt + 6 = Account Setting Page Alt + 7 = Account Privacy Configuration Page Alt + 8 = Facebook Fan Page ( Facebook Profile ) Alt + 9 = Fb Terms and Statement (Rights & Responsibilities ) Alt + 0 = Facebook Help Center Alt + ? = Search Box ( Search Option ) Facebook Short Cuts Keys For Mozilla Firefox Shift + Alt +...