Subscribe To Our Newsletter

Sign Up Now To Get Free Coupon Codes, Event Coupon Codes Updates, Offers Updates. It's 100% Free!

We Hate Spam! Really, It's terrible and we never do it.

Online Database Creation PHP Code with SQL Contribution

Now you don't need to browse PHPMyAdmin for creating database user password by database wizard. You just need to upload this files on your server and create database automatically.

1st file is style sheet file. : stylesheet.css

 @charset "utf-8";  
 /* CSS Document for : http://www.QWC.Me */  
 #dbcreation{padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  
 table{border-top-left-radius:25; border-top-right-radius:25;}  
 th{text-align:center; background-color:#999;}  
 table, th, td, tr, thead, tbody{padding: 10px;}  
 a{text-decoration:none;}  
 .error{color:red;}  
 #dbinstall{border:10; border-color:#999; border-top-left-radius:25; border-top-right-radius:25; border-bottom-left-radius:25; border-bottom-right-radius:25; padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  
 #signupform{text-shadow:#999; padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  

2nd file is Database Values Taken File : create_database.php

 <?php  
      session_start();  
 ?>  
 <!DOCTYPE html >  
 <html xmlns="http://www.w3.org/1999/xhtml" lang="us-en">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <link rel="stylesheet" href="css/stylesheet.css" />  
 <title>Database Creation Process</title>  
 </head>  
 <body>  
   <div id="dbcreation">  
     <table align="center">  
          <thead>  
            <tr><th colspan="2" align="center">Enter Database Detail</th></tr>  
       </thead>  
       <tbody>  
         <form action="install.php" method="post">  
         <tr><td><label id="host">Host: </label></td><td><input type="text" name="host" placeholder="i.e. locahost" required="required" /></td></tr>  
         <tr><td><label id="dbname">Database Name: </label></td><td><input type="text" name="dbname" required="required" /></td>  
         <tr><td><label id="dbuname">User Name: </label></td><td><input type="text" name="dbuname" placeholder="i.e. root" required="required" /></td>  
         <tr><td><label id="dbpass">Password: </label></td><td><input type="text" name="dbpass" required="required" /></td>  
         <tr><td colspan="2" align="center"><input type="submit" name="submit" Value="Create" required="required" /></td></tr>  
         </form>  
       </tbody>  
     </table>  
   </div>   
 </body>  
 </html>  


3rd file is Database installation file : install.php

 <?php  
      session_start();  
 ?>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <link rel="stylesheet" href="css/stylesheet.css" />  
 <title>Database Installation Process</title>  
 </head>  
 <body>  
 <div id="dbinstall">  
   <?php       
                //Get values from create_database.php files  
                if(isset($_POST['submit']))  
                {  
                     echo '<form method="post">  
                     <input type="hidden" name="host" value="'.$_POST['host'].'">  
                     <input type="hidden" name="dbname" value="'.$_POST['dbname'].'">  
                     <input type="hidden" name="dbuname" value="'.$_POST['dbuname'].'">  
                     <input type="hidden" name="dbpass" value="'.$_POST['dbpass'].'">  
                     <input type="submit" name="install" value="Install" align="center">  
                     </form><br/>';   
                     echo 'Welcome to installation process....<br/>  
                     Click install Button to install database.....<br />';  
                }                 
                //if user click on install button then install database on site  
                if(isset($_POST['install']))  
                {            
                     $dbhost = $_POST['host'];  
                     $dbname = $_POST['dbname'];  
                     $dbuname = $_POST['dbuname'];  
                     $dbpass = $_POST['dbpass'];  
                     //connect to mysql server for connecting server : need to give local host and user name  
                     $connect = mysqli_connect($dbhost, 'root');                 
                     //database creation.   
                     $db_create_query = "Create database " . $dbname;  
                     $database = mysqli_query($connect, $db_create_query);  
                     //database creation query error show  
                     if(!isset($database))  
                          {  
                               die("<div class=\"error\">Database creation query error : " . mysqli_connect_error() . "</div>");  
                          }  
                     //database users password query creation  
                     $dbuserpass = "create user " . $dbuname."@".$dbhost. " identified by '".$dbpass."'";  
                     $dbuserpass2 = mysqli_query($connect, $dbuserpass);  
                     //database users password query Error  
                     if(!isset($dbuserpass2))  
                          {  
                               die("<div class=\"error\">Database Username Password query error : " . mysqli_connect_error() . "</div>");  
                          }  
                     //give grant privileges to database user pass  
                     $previleges = "GRANT ALL PRIVILEGES ON $dbname. * TO '$dbuname'@'$dbpass' WITH GRANT OPTION";  
                     $previleges2 = mysqli_query($connect, $previleges);  
                     //check previleges error  
                     if(!isset($previleges2))  
                          {  
                               die("<div class=\"error\">Database Username Password query error : " . mysqli_connect_error() . "</div>");  
                          }                      
                     else  
                          {  
                               echo "Database has been created successfully<br />  
                                         Database Name :" . $dbname. "<br /> Database User Name : ".$dbuname."<br /> Database Password : ".$dbpass;  
                          }  
                }  
                session_destroy();  
      ?>  
 </div>  
 </body>  
 </html>  


I hope you will learn from it. copy code and check it

Share this article :

+ comments + 1 comments

November 5, 2013 at 2:20 AM

I'll use this script in future. It will save my time and can use it for my Getacho Company Clients.

Post a Comment

Give your reviews about this blog. Leave your comments. what do you think about this post?

Comments Description is given below:
1) I love to read comments, but do not spam.
2) Like this blog and also tweet its posts.
3) You can use some xHTML tags.
4) All Comments are Do Follow, Please try to use blog professionally.
5) Mention Your Name below the comment.
6) You can also suggest for improvement.
7) Do not forget to subscribe Samee Articles blog.

---------------------------------------
Thanks for visiting QWC.Me.
==========================================
For free guidelines contact me on SEO Expert | Samee Ullah Feroz is online there.
==========================================
Best Regards

 
Support : | Internet Marketing Specialist And Business Developer
Copyright © 2013-2016. Samee Articles - All Rights Reserved
Proudly powered by Blogger