Jump to content

Recommended Posts

ok so i would like it so when someone registers it creates a database for them. example:

 

if($_POST['submit']) {
//some code to create a database with the variable $databasename 
}
else {

<form action="<?php echo $SCRIPT_NAME ?>" method="POST">
<table>
<tr>
<td>Database name</td>
<td><input type="text" name="dbname"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Re-type Password</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register!"></td>
</tr>
</table>
</form>

}

 

like that so that it creates your own database with the name like "fred" so it would create a database called "fred"

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/103509-solved-creating-database-with-php/
Share on other sites

U want a database for each user? Never heard of such approach, and guess ill never will. Even one table for one user in the same database, would be no-sense. Probably u need this for a specific requirement, so explain better.

 

The code anyway is:

 

<?php
$dbname = $_POST['dbname'];
mysql_query("CREATE DATABASE $dbname");
?>

 

As for the username and password for each db, normally u connect to one database server and have different databases with one username, password. I guess this goes to creating users and assigning permissions, so it is beyond my php knowledge (if it can be done with php anyway!!).

 

Ud want to create tables also for them and the syntax is "CREATE TABLE user(name TINYTEXT, .....". Search in google and u'll be suprised on how much information ull get.

i tried this:

 

<?php
session_start();

require("config.php");

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);

if($_POST['submit']) {

$dbname = $_POST['dbname'];
mysql_query("CREATE DATABASE $dbname");


//some code to create a database with the variable $databasename 
}
else {
?>
<form action="<?php echo $SCRIPT_NAME ?>" method="POST">
<table>
<tr>
<td>Database name</td>
<td><input type="text" name="dbname"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Re-type Password</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register!"></td>
</tr>
</table>
</form>
<?php
}
?>

 

didnt create the database lol I'm doing something wrong

 

quick example for u....



<?php
include 'config.php';
include 'opendb.php';

$query  = 'CREATE DATABASE phpcake';
$result = mysql_query($query);

mysql_select_db('phpcake') or die('Cannot select database');

$query = 'CREATE TABLE contact( '.
         'cid INT NOT NULL AUTO_INCREMENT, '.
         'cname VARCHAR(20) NOT NULL, '.
         'cemail VARCHAR(50) NOT NULL, '.
         'csubject VARCHAR(30) NOT NULL, '.
         'cmessage TEXT NOT NULL, '.
         'PRIMARY KEY(cid))';

$result = mysql_query($query);

include 'closedb.php';
?>

so your saying this would work?

 

<?php


require("config.php");

$db = mysql_connect($dbhost, $dbuser);


if($_POST['submit']) {

$dbname = $_POST['dbname'];
mysql_query("CREATE DATABASE $dbname");


//some code to create a database with the variable $databasename 
}
else {
?>
<form action="<?php echo $SCRIPT_NAME ?>" method="POST">
<table>
<tr>
<td>Database name</td>
<td><input type="text" name="dbname"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Re-type Password</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register!"></td>
</tr>
</table>
</form>
<?php
}
?>

 

well it doesn't

kindly change this line and your piece of code should work

 

<td><input type="submit" value="Register!"></td>

 

to

 

<td><input type="submit" value="Register!" name="submit"></td>

 

your if condition is not getting executed .

 

Hope it works!!

 

Thanks I'm stupid when it comes to errors

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.