I'm trying to create a database with CREATE DATABASE command, but instead it gives me an error. this is my code:
$db_usr = mysql_real_escape_string($_POST["email"]);
$con=mysql_connect("localhost","root");
if (! $con)
{
die('Could not connect: ' . mysql_error());
}
else
{
test();
}
function test()
{
$sql = "CREATE DATABASE '$db_usr'";
mysql_query($sql);
}
It always returns "Undefined variable"
mysql_query
, since it's deprecated. If you can't/aren't going to use PDO, use themysqli
library. Please see the PHP docs. – Joshua Smock Oct 19 '13 at 9:03mysql_connect("localhost","root");
// you forgot to keep password – user2092317 Oct 19 '13 at 9:04