Jump to content


Photo

Create Table problem


  • Please log in to reply
8 replies to this topic

#1 NME

NME
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 May 2006 - 04:13 AM

I am trying to dynamically create a table with a different name everytime. The following code is used, but it never seems to actually create a Table when i look at the database.

$dbhost = '<myhost>';
$dbusername = '<myusername>'; 
$dbpasswd = '<mypassword>'; 
$database_name = '<mydatabasename>'; 

$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")  
    or die ("Couldn't connect to server."); 
$db = mysql_select_db("$database_name", $connection) 
    or die("Couldn't select database."); 


$sql = mysql_query ( "CREATE TABLE user_" . $userid . " (
        index int(25) NOT NULL auto_increment,
        count int(25) NOT NULL,
        PRIMARY KEY (index)
        )");
                

Any ideas why nothing is happening?

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 May 2006 - 05:00 AM

Change :
PRIMARY KEY (index)
to
PRIMARY KEY (`index`)

It may help ;)
~ D Kuang

#3 NME

NME
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 May 2006 - 05:10 AM

Thanks, but it stil doesnt create me a table.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 May 2006 - 05:15 AM

Do this:

mysql_query(QUERY_HERE) or die (mysql_error())

This should help you know what's going on
~ D Kuang

#5 NME

NME
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 May 2006 - 05:29 AM

Ok, this is what is says, but i still cant figure it out:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'int(25) NOT NULL auto_increment, freinds int(25) NOT NULL,

#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 May 2006 - 05:35 AM

OK, Try this:

$sql = mysql_query(" 
CREATE TABLE `user_$userid` (
  `index` INT( 25 ) NOT NULL AUTO_INCREMENT ,
  `count` INT( 25 ) NOT NULL ,
  PRIMARY KEY ( `index` ) 
);") or die(mysql_error());


This should work.
~ D Kuang

#7 NME

NME
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 May 2006 - 05:48 AM

hmm im still getting an error:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''Info_User_19' ( 'index' INT( 25 ) NOT NULL AUTO_INCREMENT ,

by the way, thanks so much for all your time poirot.

#8 NME

NME
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 26 May 2006 - 06:22 AM

any help would be really appreciate guys

#9 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 26 May 2006 - 08:00 AM

I think the query poirot gave you should work unless and until you mis-interpreted the backt tick "`" to be a single quote.
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users