The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Created a table in phpMyAdmin comes up with error when tested

Discussion in 'Database Discussions' started by Scotty13, Sep 18, 2011.

  1. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    <?php
    require_once "connect_to_mysql.php";
    print "Success in database CONNECTION.....<br />";
    $result = "CREATE TABLE members (
    id int(11) NOT NULL auto_increment,
    username varchar(255) NOT NULL,
    city varchar(255) NOT NULL,
    state_province varchar(255) NOT NULL,
    country varchar(255) NOT NULL,
    bio_body text NULL,
    email varchar(255) NOT NULL,
    website varchar(255) NULL,
    youtube varchar(255) NULL,
    made_res_date datetime NOT NULL default '0000-00-00',
    last_ckin_date datetime NOT NULL default '0000-00-00',
    account_type enum('a','b','c') NOT NULL default 'a',
    email_activated enum('0','1') NOT NULL default '0',
    PRIMARY KEY (id),
    UNIQUE KEY email (email)
    )";
    // This line uses the mysql_query() function to create the table now
    $queryResult = mysql_query($tableCreate);
    // Create a conditional to see if the query executed successfully or not
    if ($queryResult === TRUE) {
    print "<br /><br />Success in TABLE members creation! Happy Coding!";
    } else {
    print "<br /><br />No TABLE created. Check";
    }
    // close mysql connection
    mysql_close();
    ?>

    I'm going crazy! Why do I keep getting this message when I test it in my browser (IE)?

    Success in database CONNECTION.....

    No TABLE created. Check

    Thanks in advance, Scotty:confused:
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Does the table already exist in the database?
     
  3. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Yes, it matches to a "T" in my phpMyAdmin. I actually have 11 tables under my database and they all come up with the same answer.
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    You cannot create a table that already exists. The table has to be dropped before creating it.
     
  5. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Now I’m really confused. I’m new to all this so please be patient. I’m following tutorials from a person who is teaching people how to make social network websites. I build my table.php in Dreamweaver CS4, build my table in phpmyadmin, and upload in FTP / Filezilla.
     
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    If the table already exists, your script cannot create it again. You'd have to drop the table and then test the script to create a table that doesn't already exist.
     
  7. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I forgot to mention, when I test table.php in my browser and everything is “OK” then I go and delete it out of my Remote site.
     
  8. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    This script creates a table called members in MySQL. The table that I'm speaking about already existing would be members in PhpMyAdmin not a PHP script itself.
     
  9. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    The table members does exist in phpMyAdmin.
     
  10. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Then your script cannot create it for that reason. You have to drop the table members to use a script to create a table called members. Otherwise, your script needs to add the following before creating it:

    Code:
    drop table if exists members;
    That's just how it works. You cannot create what already exists.
     
  11. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    SO, do I keep the script (php file) or do I keep the table under my database? Thank you so much, Scotty
     
  12. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    The table in the database is what already exists and is preventing the script from working to create it. If what you are testing is the script working, you need to remove the table members in your database. Otherwise, you need to add the drop table syntax I noted into the script before the table creation.
     
  13. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I made a new php file named memberss.php (didnt make a table in my database), uploaded to FTP, tested in my browser and got the same error...

    Success in database CONNECTION.....

    No TABLE created. Check
     
  14. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    The script isn't the issue. It is that the table members exists in the database. Change the table in the script to one that doesn't exist or drop the table that already exists in the database. Renaming the file itself doesn't change the code trying to create a table that exists already called members.
     
  15. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I notice my tables are ALL listed under my "mysqlconn" file located under the DATABASES tab in Dreamweaver and my connection tested successfull.
     
  16. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I deleted a table in my database made a new one, changed it, etc came up with the same error.
     
  17. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Can you explain what is meant by "made a new one" in your last response? As I mentioned, you cannot create the table before running the script. The table cannot exist already that needs to be created by the script.

    If you are learning and that's the purpose of the script, this lesson would be that a script to create a table must create a new table that does not exist. If the table exists, the script you are using won't work because it doesn't drop the table first in the script before trying to create it.
     
  18. Scotty13

    Scotty13 Member

    Joined:
    May 21, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I figured it out. Got them ALL working. Thanks, Scotty
     
Loading...

Share This Page