Jump to content

script does nothing :S


Recommended Posts

Hi, I would be gratefull if someone could tell me why this script doesn't actually load. All that happens is that the browser loads a blank page. Can someone tell me where I've gone wrong. Thanks Callum

<!-- Create db form --><?php   $conn = @mysql_connect( "localhost", "root", "" )	or die( "Could not connect to MySQL" );$rs1 =	@mysql_create_db( $_REQUEST['db'] );$rs2= 	@mysql_list_dbs($conn);$list = "";for( $row=0; $row < mysql_num_rows( $rs2 ); $row++ ){   $list .= mysql_tablename( $rs2, $row ) . " | "; } ?><html> <head>  <title>Admin Tools</title> </head> <body> <form action="<?php echo( $_SERVER['PHP_SELF'] ); ?> " method="post"> Current databases: <?php echo( $list ); ?>  <hr> Name:<input type = "text" name = "db">  <input type = "submit" value = "Create database"> </form> </body></html>

Link to post
Share on other sites

thanks, the new error message is.Fatal error: Call to undefined function mysql_create_db() in C:\wamp\www\newfolder\proj1\create_db.php on line 8I do not understand? :S i thought that was a defined function :S

Link to post
Share on other sites

Your host may have disabled it because they don't want you to freely create DBs...

Link to post
Share on other sites

This is on my own test host using Wampserver2 though :S. if it helps im running MYSQL 5.0.51bEDIT: Uploaded the script to my online host and I get exactly the same error.Is both my local test server and my online host blocking me from creating DB's? Or is my code incorrect :S

Link to post
Share on other sites

I used this code and it works great but i think that the problem is not the code :/

<?php$con = mysql_connect("localhost","root","");if (!$con)  {  die('Could not connect: ' . mysql_error());  }// Create databaseif (mysql_query("CREATE DATABASE my_db",$con))  {  echo "Database created";  }else  {  echo "Error creating database: " . mysql_error();  }// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE something(something,something,something)";// Execute querymysql_query($sql,$con);

Link to post
Share on other sites

EDIT: Moved on, starting to get the hang of it.EDIT 2: Does every MYSQL database need a primary key??, if so is it possible to set a primary key without deleting the table ???(table is empty at the moment but I don't want to delete it)

Link to post
Share on other sites
EDIT 2: Does every MYSQL database need a primary key??, if so is it possible to set a primary key without deleting the table ???(table is empty at the moment but I don't want to delete it)
Databases don't have primary keys, tables do. A table doesn't need one, but it will help speed up lookups if you choose a primary key that makes sense. Almost always I create a new column to be the primary key and make it an int autoincrement field. You can use an ALTER TABLE query to define a primary key on an existing table.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...