Create a Database using PHP Script



File name: create_database.php
<!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" />
                        <title>Database Create</title>
            </head>
<body>
            <div align="center">
                        <h1> Database Information </h1>
                        <form action="create_database.php" method="post" name="db"> <br  />
                                    <input name="host" type="text" value="localhost" /> <br  />
                                    <input name="user" type="text" value="root" /> <br  />
                                    <input name="pass" type="password" value="" /> <br  />
                                    <input name="db" type="text" value="" /> <br  /><br  />
                                    <input name="submit" type="submit" value="Create Database" /> <br  />
                         </form>
            </div>
</body>
</html>
<?php
$dbhost=$_REQUEST['host'];
$dbusername=$_REQUEST['user'];
$dbuserpass=$_REQUEST['pass'];
$dbname=$_REQUEST['db'];
if($dbhost!="" && $dbusername!="" && $dbname!="") {
$con = mysql_connect ($dbhost, $dbusername, $dbuserpass) or mysql_error();
if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
mysql_select_db("$dbname");
            $info = "CREATE TABLE info (
            id int(11) NOT NULL auto_increment,
            name varchar(255) NOT NULL,
            address varchar(255),
            cell varchar(255),
            PRIMARY KEY(id) )";
        $results = mysql_query($info) or die (mysql_error());
        echo "Database create successfully !!";
 }
        else 
           echo "Dose not empty any field !!";
?>  

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle