#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    14
    Rep Power
    0
    Here is the error I get:


    Error in executing CREATE TABLE %s (cityname VARCHAR (20), KEY index_name
    (cityname(10)), dow1 VARCHAR (9), max1 TINYINT, min1 TINYINT, sky1 VARCHAR (20), fcstdays TINYINT)
    stmt

    error: 1064 You have an error in your SQL syntax near ' dow1 VARCHAR
    (9), max1 TINYINT, min1 TINYINT,&nbs' at
    line 1


    Here is the actual code for this page:

    <?php



    require ("common.php3");

    //CREATE TABLE STATEMENT BASED ON NUMBER OF FORECAST DAYS


    $one = "CREATE TABLE %s (cityname VARCHAR (20), KEY index_name (cityname(10)),";

    for ($i = 1; $i <= $fcstdays; $i++):
    $one = $one . "&nbsp;" . "dow$i" . "&nbsp;" . "VARCHAR (9)," . "&nbsp;" .
    "max$i" . "&nbsp;" . "TINYINT," . "&nbsp;" .
    "min$i" . "&nbsp;" . "TINYINT," . "&nbsp;" .
    "sky$i" . "&nbsp;" . "VARCHAR (20)," . "&nbsp;";
    endfor;

    $stmt = $one . "&nbsp;" . "fcstdays" . "&nbsp;" . "TINYINT" . ")";


    $hostName ="xxxx";
    $userName ="xxxx";
    $password ="xxxx";
    $databaseName ="xxxx";

    //FUNCTION TO CREATE ERROR MESSAGE

    function printError ($errorMesg)
    {
    printf("<BR> %s <BR>n", $errorMesg);
    }

    // OPEN CONNECTION WITH THE DATABASE SERVER

    if (!($link=mysql_connect($hostname, $userName, $password))) {
    printError(sprintf("error connecting to host %s, by users %s", $hostName, $userName));
    exit();
    }

    // SELECT THE DATABASE

    if (!mysql_select_db($databaseName, $link)) {
    printError(sprintf("Error in selecting %s database", $databaseName));
    printError(sprintf("error:%d %s", mysql_errno($link), mysql_error($link)));
    exit();
    }

    // CREATE THE TABLE

    if (!mysql_query(sprintf($stmt,$tablename), $link)) {
    printError(sprintf("Error in executing %s stmt", $stmt));
    printError(sprintf("error: %d %s", mysql_errno($link), mysql_error($link)));
    exit();
    }

    printf("<BR> Created Table %s.%s <BR>n", $databaseName, $tablename);

    ?>

    Any idea?, somebody help, been stearing at screen for hours now
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    first of all you can't give table name with '%s' value.

    and cityname should be NOT NULL field becoz that is unique or index field.


    your query should be something like this..


    CREATE TABLE test(cityname VARCHAR (20)not null, KEY index_name
    (cityname(10)), dow1 VARCHAR (9), max1 TINYINT, min1 TINYINT, sky1 VARCHAR (20), fcstdays TINYINT);

    just create a query like above with concatenation.




    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. error using the useBean tag in JSP
    By naz in forum Java Help
    Replies: 7
    Last Post: June 7th, 2004, 02:53 PM
  2. PHP Error
    By xellos16 in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 04:38 AM
  3. problems about perl dbi installation...
    By lee_sv@yahoo.co in forum Perl Programming
    Replies: 0
    Last Post: July 9th, 2003, 02:01 PM
  4. Creating a MySQL table error
    By mizzory in forum PHP Development
    Replies: 4
    Last Post: August 31st, 2002, 12:15 AM
  5. server full - creating a error message
    By trembler in forum Apache Development
    Replies: 0
    Last Post: September 14th, 2001, 10:37 AM

IMN logo majestic logo threadwatch logo seochat tools logo