I tried just your example in a file, substituting proper values for the variables and got the same message. My entire php file was just the above code you posted. It worked if I used the name of a database that existed at one point. But if I tried a brand new database name, error message.
Here is the function I have to create a database. It does work and create a database, if the database at one time existed but was deleted. It will not create a brand new database though.
Connection part of page
I used variables for my connection string because they are in another file.
$host = localhost
$user = cpanel_username
$password = cpanel_username_password
>include('connection_info');
$conn = mysql_connect( $host, $user, $password )
or die ("Sorry - could not connect to MySQL");
>function create_database($db)
{
$db = "cpanelname_". $db;
if (mysql_query("CREATE DATABASE $db")) {
echo "Database created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
return $db;
}
And here is where the function is called.
>Case 'add':
print '<form action="' . $PHP_SELF . '?choice=add_db" method="post">';
print 'Current databases: '; echo($db_list);
print ' <hr>';
print '<br>';
print 'Name:<input type="text" name="db">';
print '<input type="submit" value="Create Database">';
print '</form>';
break;
Case 'add_db':
create_database($db);
break;
The page that I have created uses links to do things like list databases, list the tables in each database, create a database, delete a database, and create a table in an existing database.
When a link is clicked, the link uses $PHP_SELF and adds in a variable to be used in the case statement.
So, for the add database link, it uses $PHP_SELF?choice=add
Then goes into the add case and creates a form to get the name of the database to create(variable is db) and submits it using $PHP_SELF?choice=add_db
to fall into the next case where the create_database($db) function is called.
If this post doesn't help, I can paste in my entire page and move it to a location that isn't password protected, for the moment, so that it can be viewed.
Thanks so far for all the replies