Unable to create database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
onlykishor
Forum Newbie
Posts: 2
Joined: Tue Feb 28, 2006 2:34 am
Contact:

Unable to create database

Post by onlykishor »

Hi All,

Help me out for the below code. Able to list all the existing database but new database is not getting created. I'm using PHP 5 on MySql 4.0 (there is no default password set for MySql)

Code: Select all

<?
$conn = @mysql_connect("localhost","root") or die("Unable to connect : " . mysql_error() );
if ( strlen($dbname) > 0 )
{
	$sql = 'CREATE DATABASE $dbname';
	if (mysql_query($sql, $conn)) {
   	    echo "Database created successfully\n";
	} else {
	    echo 'Error creating database: ' . mysql_error() . "\n";
	}
} else {
	echo "<br>please specify database name to create<br>" ;
}

$rs = @mysql_list_dbs($conn);

for($row=0; $row < mysql_num_rows($rs); $row++)
{
	$list .= mysql_tablename($rs, $row) . " | " ;
}
mysql_close($conn);
?>

<html><head><title>Create Databases</title></head>
<body>

<form action="<? echo($PHP_SELF); ?>" method="post">
Current databases: <? echo($list); ?> <hr>
Name: <input type="text" name="dbname">
<input type="submit" value="Create Database">

</form>
</body>
</html>
Thanks in advance..
Kishor.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Where's $dbname coming from?
onlykishor
Forum Newbie
Posts: 2
Joined: Tue Feb 28, 2006 2:34 am
Contact:

Thanks for reply

Post by onlykishor »

The $dbname is coming from the HTML at the end of script.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Only if register_globals is on. Is it?
Post Reply