A Step by Step approach for PHP-MySQL Connectivity Using XAMPP Server
Step I Downloading and Installing XAMPP
What we Require? 1. XAMPP Server(32 bit/64 bit) 2. Editor(Notepad++/Netbeans) 3. Any Latest Browser(Internet Explorer/Chrome/Mozila Firefox)
• Download Latest Version of XAMPP(32/64 bit, according to your machine) from apachefriends.org • An .exe file will be downloaded after few minutes. •
• Now Double Click on Downloaded exe file of XAMPP. It will be started to install. • There can a warning message shown as in following snapshot. Just click on Ok (because it is related with user account control, will be discussed later sometime).
• After few minutes, XAMPP will be installed.XAMPP comes with its Control Panel. This control panel is used to start/stop any service directly. It will prompt to open Control panel. You can open now or later on. I will open to check the installation status of XAMPP. • After clicking on finish, Save appropriate language. • Now Following snapshot shows XAMPP control panel.
• Now start Apache and MySQL services by clicking on Start Buttons shown in front of them.Now, lets check the working of server. • Open any Browser.(I will open Chrome). • Type localhost in address bar and hit enter.The following screen shows successful working of XAMPP.
Step II Creating Database and Table in MySQL
• Open XAMPP Control Panel.It can be opened by moving to C:xampp directory.Serach xampp-control file and click on it. • Now click on Admin button in front of MySQL Module.It will open MySQL database user interface in default browser as shown. • You can create and manage databases in this interface. It can be also openend by typing http://localhost/phpmyadmin/ in address bar.
MySQL Database User Interface
Creating Database • Click on database Tab. • Now type name of database you want to create.I type user_account. Then click on create button. • Now new database with name user_accounts will be created and shown on the top in hierarchical way.
Creating Table • Now give a tablename to be created and select number of columns. Click on go to proceed further. • I have typed two columns say, user_id and user_passwd for my table.Click on save to process query. A table will be created as shown.
Step III Connecting PHP and MYSQL to insert into table
• Open Notepad++ to type following coding.Save this file to C:xampphtdocs for proper working.
Form Coding
Form Coding (user_register.php) </head> <body> <form id="user_register" method="get" > <div style="text-align:center"> <span class="label success" height="100%"><font size="4">Enter User Id</font></span> <input type="text" id="un" name="uname" placeholder="Enter User Name"> <br/> <span class="label success" height="100%"><font size="4">Enter User Id</font></span> <input type="password" id="up" name="upasswd" placeholder="Enter Password"> <br/><br/> <input type="submit" name="submit" value="Add User">
Form Coding (user_register.php) cont. <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "user_accounts"; //creating connection $con = new mysqli($servername, $username, $password, $dbname); //checking connection status if($con->connect_error) { die("Connection Failure:".$conn->connect_error); return false; }
Form Coding (user_register.php) cont. if(isset($_GET['submit'])) { $u_name=$_GET['uname']; $u_passwd=$_GET['upasswd']; $add_qry="insert into users_tabs(user_id,user_passwd)values('$u_name','$u_passwd')"; if ($con->query($add_qry) === TRUE) { echo "User Added"."<br/>"; } else {echo "Error: " . $add_qry . "<br>" . $con->error;} unset($_GET['submit']); $con->close(); } ?> </div></form><body></html>
Output
Database Snapshot
Conclusion • So, hence you can execute every type of query such as insert, select, delete and update in MySql.
Thanks

PHP-MySQL Database Connectivity Using XAMPP Server

  • 1.
    A Step byStep approach for PHP-MySQL Connectivity Using XAMPP Server
  • 2.
  • 3.
    What we Require? 1.XAMPP Server(32 bit/64 bit) 2. Editor(Notepad++/Netbeans) 3. Any Latest Browser(Internet Explorer/Chrome/Mozila Firefox)
  • 4.
    • Download LatestVersion of XAMPP(32/64 bit, according to your machine) from apachefriends.org • An .exe file will be downloaded after few minutes. •
  • 5.
    • Now DoubleClick on Downloaded exe file of XAMPP. It will be started to install. • There can a warning message shown as in following snapshot. Just click on Ok (because it is related with user account control, will be discussed later sometime).
  • 7.
    • After fewminutes, XAMPP will be installed.XAMPP comes with its Control Panel. This control panel is used to start/stop any service directly. It will prompt to open Control panel. You can open now or later on. I will open to check the installation status of XAMPP. • After clicking on finish, Save appropriate language. • Now Following snapshot shows XAMPP control panel.
  • 8.
    • Now startApache and MySQL services by clicking on Start Buttons shown in front of them.Now, lets check the working of server. • Open any Browser.(I will open Chrome). • Type localhost in address bar and hit enter.The following screen shows successful working of XAMPP.
  • 9.
    Step II Creating Databaseand Table in MySQL
  • 10.
    • Open XAMPPControl Panel.It can be opened by moving to C:xampp directory.Serach xampp-control file and click on it. • Now click on Admin button in front of MySQL Module.It will open MySQL database user interface in default browser as shown. • You can create and manage databases in this interface. It can be also openend by typing http://localhost/phpmyadmin/ in address bar.
  • 11.
  • 12.
    Creating Database • Clickon database Tab. • Now type name of database you want to create.I type user_account. Then click on create button. • Now new database with name user_accounts will be created and shown on the top in hierarchical way.
  • 13.
    Creating Table • Nowgive a tablename to be created and select number of columns. Click on go to proceed further. • I have typed two columns say, user_id and user_passwd for my table.Click on save to process query. A table will be created as shown.
  • 14.
    Step III Connecting PHPand MYSQL to insert into table
  • 15.
    • Open Notepad++to type following coding.Save this file to C:xampphtdocs for proper working.
  • 16.
  • 17.
    Form Coding (user_register.php) </head> <body> <formid="user_register" method="get" > <div style="text-align:center"> <span class="label success" height="100%"><font size="4">Enter User Id</font></span> <input type="text" id="un" name="uname" placeholder="Enter User Name"> <br/> <span class="label success" height="100%"><font size="4">Enter User Id</font></span> <input type="password" id="up" name="upasswd" placeholder="Enter Password"> <br/><br/> <input type="submit" name="submit" value="Add User">
  • 18.
    Form Coding (user_register.php)cont. <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "user_accounts"; //creating connection $con = new mysqli($servername, $username, $password, $dbname); //checking connection status if($con->connect_error) { die("Connection Failure:".$conn->connect_error); return false; }
  • 19.
    Form Coding (user_register.php)cont. if(isset($_GET['submit'])) { $u_name=$_GET['uname']; $u_passwd=$_GET['upasswd']; $add_qry="insert into users_tabs(user_id,user_passwd)values('$u_name','$u_passwd')"; if ($con->query($add_qry) === TRUE) { echo "User Added"."<br/>"; } else {echo "Error: " . $add_qry . "<br>" . $con->error;} unset($_GET['submit']); $con->close(); } ?> </div></form><body></html>
  • 20.
  • 21.
  • 22.
    Conclusion • So, henceyou can execute every type of query such as insert, select, delete and update in MySql.
  • 23.