SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Create table not working

    I used PHP to create a table, and it worked. I then tried to create a second table and this one failed.

    PHP Code:
    <?php
    error_reporting
    (-1);
    ini_set('display_errors'true);

    $server"************";     /* Address of database server */ 
    $user="************";           /* Database username */ 
    $password="*********";          /* Database Password */
    $database="**********";        /* name of database */

    mysql_connect($server,$user,$password) or die ( "<H3>Server unreachable</H3>");
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query="CREATE TABLE two ( id varchar(50) NOT NULL default '', userid varchar(10) NOT NULL default '', ip varchar(20) NOT NULL default '', tm datetime NOT NULL default '0000-00-00 00:00:00', status char(3) NOT NULL default 'ON' ) TYPE=MyISAM;";
    mysql_query($query);
    mysql_close();
    ?>
    This is identical to what I used to create the first table, but the table does not get created (verified using PHPmyadmin). I suspect the code is not good code, but i am using it to learn, so don't worry about my feelings if it is a mess.
    Each day is a learning experience.

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,000
    Mentioned
    101 Post(s)
    Tagged
    0 Thread(s)
    Have both tables that you're trying to create got different names? I tried the create table query locally and the table created fine.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, both tables have different names. Is it necessary to have completely unique table names. The actual names I used were group_one and group_two. Would this make a difference?
    Each day is a learning experience.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by CSU-Bill View Post
    Would this make a difference?
    nope

    and you're saying that other than the table name, the tables are identical? or are you saying that the php you used is identical, but the tables have different columns?

    may i ask why you're even using php to create tables? it's not as though you were planning on creating tables over and over again (i hope)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOW! I just found the error. There is a stray ) in the code. Once I removed that ) I was able to create the table.

    I also realized that the code I posted above is for table one, which worked.

    My bad.
    Each day is a learning experience.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •