deesse Posted August 17, 2007 Share Posted August 17, 2007 Hi, I have the following php script which connects successfully to mysql....and create table. <?php $link = mysql_connect('localhost', '1345', '12345'); if (!$link) { die('Could not connect: ' . mysql_error());} $sql = 'CREATE DATABASE shop'; if (mysql_query($sql, $link)) { echo "Database shop created successfully\n"; } else { echo 'Error creating database: ' . mysql_error() . "\n"; } ?> What scripts can i add to this, instead of automatically creating a database pre-defined early but give user to input the database name and also drop it. My point is to avoid the user from doing any editing or modification to the script. Just click and get! For instance: once connected it says: input and feedback > Please enter your database name: ................... > Your database (any name) is created successfully ! > drop the database, > Are you sure you want to delete the database (Y/N) ? Could you please help me to implement the scripts...or provide examples or links. thanks for reading...! Quote Link to comment https://forums.phpfreaks.com/topic/65398-php-script-additional-needed/ Share on other sites More sharing options...
Orio Posted August 17, 2007 Share Posted August 17, 2007 You could do something as simple as: <?php if(isset($_POST['submit'])) { $link = mysql_connect('localhost', '1345', '12345') or die('Could not connect: ' . mysql_error()); if($_POST['act'] == "create") { $sql = 'CREATE DATABASE '.$_POST['name']; if (mysql_query($sql, $link)) echo "Database ".$_POST['name']." created successfully\n"; else echo 'Error creating database: ' . mysql_error() . "\n"; } else { $sql = 'DROP DATABASE '.$_POST['name']; if (mysql_query($sql, $link)) echo "Database ".$_POST['name']." dropped successfully\n"; else echo 'Error dropping database: ' . mysql_error() . "\n"; } echo "<br>"; } echo "<form action=\"".basename($_SERVER['PHP_SELF'])." method=\"POST\">"; echo "<select name=\"act\">"; echo "<option value=\"drop\">Drop</option>"; echo "<option value=\"create\">Create</option>"; echo "</select>"; echo "<br><br>DB name:<br>"; echo "<input type=\"text\" name=\"name\">"; echo " <input type=\"submit\" name=\"submit\">"; echo "</form>"; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/65398-php-script-additional-needed/#findComment-326558 Share on other sites More sharing options...
deesse Posted August 17, 2007 Author Share Posted August 17, 2007 thanks tremendously for the reply.....this is really good. It says method= was not found on this server. I am wondering if i could use include(); to add more functions/command. By the way, I am trying to query everything through command prompt. tools used: MySQL, PHP, Apache. thanks once again.... Quote Link to comment https://forums.phpfreaks.com/topic/65398-php-script-additional-needed/#findComment-326659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.