Jump to content

script does nothing :S


Callum

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 comment
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 comment
Share on other sites

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

Link to comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...