Jump to content

creating database...


dev99

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!";
}
}

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.