Jump to content

Archived

This topic is now archived and is closed to further replies.

dev99

creating database...

Recommended Posts

my script is to create a database with NO root priviliges... and i keep getting errors when i try to create one...

<?php

if (empty($_GET['mode'])) {


echo "<form action='/create_db.php?mode=process' method='post'>
<table border='0' cellpadding='2' cellspacing='0' width='100%'>
<tr>
<td valign='top' align='left'><b><u><font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular' size='-1'>Database Name:</font></u></b><br>
<td valign='top' align='left'><input name='dbname' value=''></td>
</tr>
<tr>
<td valign='top' align='left'><b><u><font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular' size='-1'>Login to Database:</font></u></b><br>
<td valign='top' align='left'><input name='username' value=''></td>
</tr>
<tr>
<td valign='top' align='left'><b><u><font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular' size='-1'>Password:</font></u></b><br>
<td valign='top' align='left'><input type='password' name='pass'></td>
</tr>
<tr>
<td valign='top' align='left'><b><u><font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular' size='-1'>Re-enter Password:</font></u></b><br>
<td valign='top' align='left'><input type='password' name='pass2'></td>
</tr>
<tr>
<td valign='top' align='middle' colspan='2'><br><input type='hidden' name='createdb' value='1'><input type='submit' value='Create Database'></td>
</tr>
</table>
</form>";
}

elseif ($_GET["mode"] == "process") {

extract($_POST);

if ($pass == $pass2) {
mysql_connect("localhost","root","mypass");
$sql = "GRANT ALL PRIVILEGES ON $dbname.* TO '$username'@'localhost' IDENTIFIED BY 'pass'";
echo $sql;
if (mysql_query($sql)) {
echo "Successfully created user account $username <p>";
} else {
echo mysql_error();
}
mysql_close();
mysql_connect("localhost",$username,$pass);
$sql = "CREATE DATABASE $dbname";
if (mysql_query($sql)) {
echo "Database $dbname created successfully!";
} else {
echo mysql_error();
}
} else {
echo "Your passwords do not match! Try again!";
}
}

?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.