Creating tables in a database

Discussion in 'PHP' started by bunny123, Feb 25, 2007.

  1. #1
    I am using this code to create a new table in a database
    I can connect to the database
    But i cannot create a new table or add data to an existing table
    I can select data from an existing table

    Is it something in my code?

    Thanks


    <?php
    $con = mysql_connect("mysql285.secureserver.net","database1","password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    echo "could not connect";
    }
    else
    {
    echo "connected";
    }


    mysql_select_db("database1", $con);
    $sql = "CREATE TABLE Prods
    (
    Product_ID bigint(100) NOT NULL AUTO_INCREMENT,
    Department varchar(20),
    Name varchar(50),
    Prod_code varchar(50),
    Description varchar (255),
    Picture varchar(50),
    Price decimal(8,2),
    Stock varchar(40),
    Prod_Type varchar(100))";

    mysql_query($sql,$con);

    mysql_close($con);

    echo "<br />";

    ?>
     
    bunny123, Feb 25, 2007 IP
  2. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mysql_query($sql) or die(mysql_error());

    Use that.
     
    Icheb, Feb 25, 2007 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mad4, Feb 25, 2007 IP
  4. bunny123

    bunny123 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok now i am getting this error any ideas??

    "Incorrect table definition; There can only be one auto column and it must be defined as a key"

    thanks for all the help!
     
    bunny123, Feb 25, 2007 IP
  5. ketan9

    ketan9 Active Member

    Messages:
    548
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    I agree with mad4 but I would like add another commend. For database handling, I would suggest using adodb rather than manually creating the wrapper from scratch. It may save you trouble.
     
    ketan9, Feb 25, 2007 IP
  6. bunny123

    bunny123 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    even when i create a table in phpmyadmin i still cannot add data to it through php
    i am using godaddy to host the site and phpmyadmin is on godaddy
    i have created a database there
    but i can only read from the database
    i cannot insert or update data or create a new table
     
    bunny123, Feb 25, 2007 IP
  7. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Copy and paste that error message into Google. You'll find lots of people who had this problem before. Works with every error message on earth.

    He has problems creating a database table and you come in here suggesting stuff like adodb and the likes? Dude, seriously, get real. :rolleyes:
     
    Icheb, Feb 25, 2007 IP
  8. ketan9

    ketan9 Active Member

    Messages:
    548
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #8
    I saw his/her code and he/she is creating the wrappers around sql calls, so to save his/her life, i suggested using adodb. I know he/she had problems with db creation and that's why i said i agree with mad4 to use phpmyadmin... dude, seriously i m real :)
     
    ketan9, Feb 25, 2007 IP
  9. bunny123

    bunny123 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i'm actually a girl!
     
    bunny123, Feb 25, 2007 IP