Forum Moderators: coopster
<!-- example for PHP 5.0.0 final release -->
<?php
$conn = @mysql_connect( "localhost", "", "" )
or die( "Sorry - 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>Creating databases</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>
[edited by: eelixduppy at 10:31 pm (utc) on Oct. 9, 2007]
[edit reason] removed specifics [/edit]
There are a few quick things I'm going to say about your code, which may or may not be the reason you are having issues. Firstly, remove the error suppression operator, @, before your functions so that you can see errors when they occur.
Secondly, the functions you are using are depreciated. You should be using mysql_query() and then the respective mysql query to get what you want. For instance, creating a database would be something like this:
$query = "CREATE DATABASE `".[url=http://www.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]$db_name)."`";
$result = mysql_query($query) or die(mysql_error());
#the 'die' expression is for debugging purposes here
The same would also go for listing the databases.
Further debugging, you may want to check your error logs and see what's going on behind the scenes. A blank screen in php usually means a fatal error somewhere in your code.