Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
metroid87706
Forum Newbie
Posts: 17 Joined: Sat Jul 14, 2007 12:06 pm
Post
by metroid87706 » Wed Aug 15, 2007 2:20 pm
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 » Wed Aug 15, 2007 2:37 pm
$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 » Wed Aug 15, 2007 2:41 pm
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.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Aug 15, 2007 3:52 pm
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.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Aug 16, 2007 3:20 am
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 » Thu Aug 16, 2007 4:11 am
or navicat.