muzammil
04-12-2011, 10:26 AM
Hi Awsome Coders. Please bear with me as i am newbie.
My question is can we name our database from taking the input from form.
For example
<html>
<head>
</head>
<body>
<form name="createDatabase" action="create.php" method="post">
Username:<input type="text" name="user" />
Password:<input type="password" name="password"/>
<input type="submit" name="submit" value="Register" />
</form>
</body>
</html>
<?php //create.php
$u=$_POST['user'];
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
All i want is name of the database should be the one that is enterd as 'username'. How can we achieve this?
My question is can we name our database from taking the input from form.
For example
<html>
<head>
</head>
<body>
<form name="createDatabase" action="create.php" method="post">
Username:<input type="text" name="user" />
Password:<input type="password" name="password"/>
<input type="submit" name="submit" value="Register" />
</form>
</body>
</html>
<?php //create.php
$u=$_POST['user'];
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
All i want is name of the database should be the one that is enterd as 'username'. How can we achieve this?