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

Post a Comment

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

Comments Guidelines:

1) I love to read comments, but please avoid spam.

2) Like this blog, share your insights, and spread the word.

3) You can use basic HTML/xHTML tags.

4) All comments are DoFollow—please use the section professionally.

5) Kindly mention your name or brand below your comment.

6) Constructive suggestions for improvement are always welcome.


Thanks for visiting Samee Articles.

========================================

Best Regards,

Samee U. Feroz

 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger