IDOXLR8 Posted July 4, 2009 Share Posted July 4, 2009 Create a new database from information sent from a form. In this example I use an external config file with global information that is needed for proper execution. This can be changed to your settings... The Script (create_db.php): <?php include("../config.php"); $con = mysql_connect($global_dbhost,$global_dblogin, $global_dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } $dbname = $_POST['databasename']; if (mysql_query("CREATE DATABASE $dbname",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } mysql_close($con); ?> The config file: <?php $global_dbType = 'mysql'; $global_dbhost = 'localhost'; $global_dbname = 'your_db_name'; $global_dblogin = 'your_username'; $global_dbpass = 'your_password'; $global_encoding = 'utf-8'; $global_rows_per_page = 20; $global_pager_items = 10; ?> The form Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled 1</title> </head> <body> <form method="post" action="create_db.php"> <input name="databasename" type="text" style="width: 287px"><input name="Submit1" type="submit" value="submit"></form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.