Create table in mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
metroid87706
Forum Newbie
Posts: 17
Joined: Sat Jul 14, 2007 12:06 pm

Create table in mysql

Post 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!
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
metroid87706
Forum Newbie
Posts: 17
Joined: Sat Jul 14, 2007 12:06 pm

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Why don't you just install PHPMyAdmin?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

or navicat.
Post Reply