Jump to content

Recommended Posts

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...!

Link to comment
https://forums.phpfreaks.com/topic/65398-php-script-additional-needed/
Share on other sites

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.

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....

 

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.