iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-14-2008, 10:10 AM
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
  #2 (permalink)  
Old 10-14-2008, 06:39 PM
fulleffect's Avatar
WebProWorld Pro
 
Join Date: Jun 2008
Location: Northeast UK
Posts: 107
fulleffect RepRank 1
Default Re: MYSQL DB creation with php and mysql command

The most important piece of code you're missing is......

Quote:
mysql_query($sql) or die(mysql_error());

"or die(mysql_error())"

This will immediately output what the error is (if any).

When i tried your code on my server, it kept giving me a permission error.

I am using Linux, cpanel/whm, which has stricter security on databases and you cant easily create a database from the php/apache environment.

What are you trying to achieve? couldn't you create a table instead, inside of a master database?

Quote:
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)
__________________

Reply With Quote
  #3 (permalink)  
Old 10-15-2008, 08:02 AM
WebProWorld New Member
 
Join Date: Sep 2008
Posts: 18
ryanhouston RepRank 0
Default Re: MYSQL DB creation with php and mysql command

hmm Lovely idea their mate about the tables in another database be a hell lot neater to thank you for the help much appreciated
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which one? PHP or MySQL dak888 Database Discussion Forum 17 11-29-2007 03:26 AM
CSV to mySQL richkoi Database Discussion Forum 14 09-14-2006 04:42 PM
MySQL 5.0 is out TrafficProducer Database Discussion Forum 15 11-29-2005 11:12 AM
NEW TO PHP mySQL richkoi Database Discussion Forum 0 06-05-2005 05:27 PM
MySQL 4.1 case510 Database Discussion Forum 2 04-17-2004 06:42 PM


All times are GMT -4. The time now is 03:47 AM.



Search Engine Optimization by vBSEO 3.3.0