Page 1 of 1

Create table in mysql

Posted: Wed Aug 15, 2007 2:20 pm
by metroid87706
How can I create a table in mysql, like this:

Code: Select all

$sql = 'CREATE TABLE `DB_NAME_HERE` ('
        . ' `topic` varchar(65) NOT NULL default \'\','
        . ' `message` varchar(65) NOT NULL default \'\','
        . ' `datetime` varchar(65) NOT NULL default \'\','
        . ' `sender` varchar(65) NOT NULL default \'\','
        . ' PRIMARY KEY (`topic`)'
        . ' ) TYPE=MyISAM AUTO_INCREMENT=0 ';
and make the table (where it says DB_NAME_HERE) the variable $dbname from this code:

Code: Select all

$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$dbname=$_POST['dbname'];
To have that ($dbname) the table name?

Thanks!

Posted: Wed Aug 15, 2007 2:37 pm
by miro_igov
$sql = 'CREATE TABLE `'.$dbname.'` ('
. ' `topic` varchar(65) NOT NULL default \'\','
. ' `message` varchar(65) NOT NULL default \'\','
. ' `datetime` varchar(65) NOT NULL default \'\','
. ' `sender` varchar(65) NOT NULL default \'\','
. ' PRIMARY KEY (`topic`)'
. ' ) TYPE=MyISAM AUTO_INCREMENT=0 ';

But this may cause mysql injection and you should learn the difference between table and database.

Posted: Wed Aug 15, 2007 2:41 pm
by metroid87706
yea, i noticed i put DBname instead of TBname, but i dont wanna change all my code.
Ill try that, and also, the injection thing, wont matter. Its a thing only me and 3 friends are gonna use.

Posted: Wed Aug 15, 2007 3:52 pm
by superdezign
metroid87706 wrote:yea, i noticed i put DBname instead of TBname, but i dont wanna change all my code.
Find->Replace...?
metroid87706 wrote:Ill try that, and also, the injection thing, wont matter. Its a thing only me and 3 friends are gonna use.
You should still learn it.

Posted: Thu Aug 16, 2007 3:20 am
by onion2k
Why don't you just install PHPMyAdmin?

Posted: Thu Aug 16, 2007 4:11 am
by miro_igov
or navicat.