Jump to content


Photo

creating database...


  • Please log in to reply
No replies to this topic

#1 dev99

dev99
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 April 2006 - 01:05 AM

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

?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users