Hi,
I am just learing PHP and I am trying to create a Mysql database from the input of a form.
Here is the script I have written.
<?php
$link=@mysql_connect("localhost","root","")
or die("sorry - could not connect to MYSQL" );
if (isset($_POST['submit']))
{
$mysql = "CREATE DATABASE IF NOT EXISTS '$_POST[db]'";
}
else
{
$rs = @mysql_list_dbs( $link );
for( $row = 0; $row < mysql_num_rows( $rs ); $row++ )
{ $list .= mysql_tablename( $rs, $row ) . " | "; }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></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>
<?php
}
?>
I know this part is wrong or at least I think it is.
$mysql = "CREATE DATABASE IF NOT EXISTS '$_POST[db]'";
Any help would be greatly appreciated.