problem creating table in an existing db

Discussion in 'PHP' started by gilgalbiblewheel, Dec 18, 2007.

  1. #1
    I have a db open but have a problem creating a table:

    // Create table in my_db database
    mysql_select_db("kjv", $con);
    $sql2 = "CREATE TABLE person ( 
    PRIMARY KEY(id) smallint, 
    recordType char, 
    book_title, 
    book smallint, 
    chapter smallint, 
    verse smallint, 
    book_spoke smallint, 
    chapter_spoke smallint, 
    verse_spoke smallint, 
    text_data longtext
    )";
    mysql_query($sql2,$con);
    PHP:
     
    gilgalbiblewheel, Dec 18, 2007 IP
  2. dptech

    dptech Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what error you get ?

    what data type is field "book_title" above in your sql ?
     
    dptech, Dec 18, 2007 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    it says:
    kjv is supposed to be the existing database which is open.

    I got my example from
    http://www.w3schools.com/php/php_mysql_create.asp
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    // Create database
    if (mysql_query("CREATE DATABASE my_db",$con))
      {
      echo "Database created";
      }
    else
      {
      echo "Error creating database: " . mysql_error();
      }
    
    // Create table in my_db database
    mysql_select_db("my_db", $con);
    $sql = "CREATE TABLE person 
    (
    FirstName varchar(15),
    LastName varchar(15),
    Age int
    )";
    mysql_query($sql,$con);
    
    mysql_close($con);
    ?>
    PHP:
    Except that I thought I should delete part of it because I don't intend to create a NEW database and the database is already open.
    My intention is to insert data from one table to the other ( created table ).
     
    gilgalbiblewheel, Dec 18, 2007 IP
  4. jainabhishek

    jainabhishek Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    dear gigal,

    first of all u connect ur database,
    then
    the table u have created in it u have to define the datatype of book-title,and give the size to recoredtype column name,
    REMEMBER : if u select datatype character or number then u have to specifie the size also.
     
    jainabhishek, Dec 18, 2007 IP