IDOXLR8 Posted July 4, 2009 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>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now