PHP MySQL Crew

Discussion in 'OT Technology' started by k2737, Jan 5, 2006.

  1. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    I am uploading a file and then inserting some info into a database about the file. (username of who uploaded it, filename, and size) But it won't add the entry to the table.

    Table is set up as:
    Code:
     
    +-----------+--------------+------+-----+---------+-------+
    | Field         | Type             | Null   | Key | Default   | Extra  |
    +-----------+--------------+------+-----+---------+-------+
    | username  | varchar(30)    |         | PRI  |             |          |
    | file_name  | varchar(100)   |        |        |             |          |
    | size          | varchar(30)    | YES  |        | NULL     |          |
    | date         | varchar(30)    | YES  |        | NULL     |          |
    +-----------+--------------+------+-----+---------+-------+
    
    And my INSERT query is as follws:
    Code:
     
    
    $add_query = "INSERT INTO user_files (username,file_name,size,date)
                        VALUES ('{$_POST['username']}', '{$_FIlES['name']}',
                        '{$_FILES['size']}','$date_stamp')";
    
    If I try to print out the values of those variables I get nothing. (except for the $date_stamp which is something I created with the date() function.

    Any ideas? :x:
     
    Last edited: Jan 5, 2006
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,914
    Likes Received:
    8
    Location:
    Los Angeles
    Well, first you must try to get the data to post before sending it to the database. Your query does not assist us in this situation, it is the rest of your code. If the data posts, then there shouldn't be any problems inserting that data into your database.

    Also, when you insert data into the database don't forget to query the database instead of write the syntax string: mysql_query($add_query);
     
  3. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    The file will upload, so I know that it is posting, and the $FILES[] array is filled with the info to upload the file right? so I don't know why it wouldn't work if I just tried to print out the file name. I found one error that I think was causing the problem with it not inserting the data into the database but I still am not sure why the $_FILES['name'] and $_FILES['size'] don't work. Unfortunatly the code is at work and I can't VPN in from here so I will post up more info in the morning. Thanks. :bigthumb:
     
  4. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Well I solved that problem and it adds the info to the database but only it the table is empty. Once there is one row in it....it won't let me add another. Any ideas?
     
  5. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Okay solved that problem as well. I just need an auto increment id field in the database and now everything works.
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,914
    Likes Received:
    8
    Location:
    Los Angeles
    That should always be the first thing created.

    alter table <table name> add field_id int auto_increment not null

    I beleive that is the correct syntax if my memory serves me right.
     
  7. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Yeah it makes sense now. I was just going to query the DB by username to pull up what files that had uploaded so I didn't think about it.
     

Share This Page