Results 1 to 5 of 5

Thread: [RESOLVED] What is wrong with this?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] What is wrong with this?

    I have the following code:
    Code:
    $query="";
    
    $queryFile = fopen('create_tables.sql', "r") or exit("Unable to open file!");
    while(!feof($queryFile))
      {
        $query = $query . fgets($queryFile);
    
      }
    fclose($queryFile);
    
    $query = str_replace("\n",'',$query);
    
    echo $query ."<br /><br /><br />";
    
    $result = mysql_query($query);
    
    echo $result;
    
    mysql_close($conn);

    inside the create_tables.sql file i have this:
    Code:
    CREATE TABLE UserTable(
    InputID int not null auto_increment, 
    Element varchar(60), 
    Username varchar(60), 
    Password varchar(60), 
    Comment varchar, 
    primary key(InputID))
    I'm new to PHP and MySQL, so i don't really know what's going wrong here. Apparently there doesn't need to be a semicolon at the end of this SQL statement?
    I'm trying to create a table with those columns. You can see the primary key.

    Database access is successful, just there's nothing being returned when that query is executed and no table is created in that database.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: What is wrong with this?

    mysql_query returns resource if successful and FALSE if not. Assign the result of mysql_query to a variable and test this variable to see if it is false, then execute mysql_error to find out what caused the error.

    PHP Code:
    if ($result === FALSE)
    {
        echo(
    mysql_error());

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: What is wrong with this?

    It said there was a problem near the primary key line, so i played around with it a bit and figured out that the error was being cause from varchar not having an argument.

    I want this column to be able to have unlimited characters in it, so should i set it to 0?

    Also on the w3schools website they don't have an argument in the varchar function (If i may call it that). http://www.w3schools.com/sql/sql_create.asp, i guessed that that made it have unlimited characters.

    Edit:
    Don't worry, after some research i discovered that changing varchar to text fixes the problem. Thanks for your help =D. I would rep you, but it says i already have.
    Last edited by Slyke; Jul 14th, 2008 at 08:32 AM.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: What is wrong with this?

    VARCHAR is a datatype. It cannot contain more than 256 character but if you want more you should use either TEXT or BLOB instead. These can grow up to 4GB in size.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: What is wrong with this?

    Yeah, just edited my previous post =D. Thank you.

Posting Permissions

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



Click Here to Expand Forum to Full Width