View Single Post
  #1 (permalink)  
Old 10-14-2008, 10:10 AM
ryanhouston ryanhouston is offline
WebProWorld New Member
 
Join Date: Sep 2008
Posts: 18
ryanhouston RepRank 0
Wink MYSQL DB creation with php and mysql command

hello, i am currently trying to make a piece of PHP code that allows me to make a database when i click a button i have the following code but it doesn't seem to work ( i have obviously put in my own mysql details ect ).

Code:
<?PHP
// Connects to your Database
mysql_connect("localhost", "my_user", "password") or die(mysql_error());
mysql_select_db("my_db") or die(mysql_error());

if ($_POST['submit']) {

// command to make database
$sql = ("CREATE DATABASE my_db");

// creates the database
mysql_query($sql);

// database created message
echo "Database created sucessfully";

}

else {

// datebase not created message
echo "Database creation failed";

}

?>
<html>
<body>
<div align="center">
  <form name="form1" method="post" action="">
    <label>
    <input name="submit" type="submit" id="submit" value="Install">
    </label>
    </form>
  </div>
</body>
</html>
Reply With Quote