Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fileupload help?

    i have been trying to make a file upload script all the rest of the code works fine but when i come to view the file i get these errors
    Code:
    Warning:  mysql_result(): supplied argument is not a valid MySQL result resource in /home/content/b/r/a/****/html/test/show.php on line 6
    
    Warning:  mysql_result(): supplied argument is not a valid MySQL result resource in /home/content/b/r/a/****/html/test/show.php on line 7
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/b/r/a/****/html/test/show.php:6) in /home/content/b/r/a/*****/html/test/show.php on line 8
    this is my code

    PHP Code:
    <?php
    mysql_connect
    ("host""username""pw");
    mysql_select_db("db_name");
    $query "SELECT data,filetype FROM uploads where id=$id";
    $result MYSQL_QUERY($query);
    $data MYSQL_RESULT($result,0,"data");
    $type MYSQL_RESULT($result,0,"filetype");
    Header"Content-type: $type");
    print 
    $data;
    ?>
    any help would be much appricated.
    -Googleit

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I don't see where $id is set?

    This can be the result of a failure to connect as well.
    You can pop this in there to see if there was an error.
    print (mysql_error());
    Last edited by nikkiH; 11-29-2006 at 09:48 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH View Post
    I don't see where $id is set?

    This can be the result of a failure to connect as well.
    You can pop this in there to see if there was an error.
    print (mysql_error());
    tryed that didnt do nothing..
    he is where $id is set

    PHP Code:
    <?php
    mysql_connect
    ("""""");
    mysql_select_db("");
    $data addslashes(fread(fopen($form_data"r"), filesize($form_data)));
    $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ""VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
    $idmysql_insert_id();
    print 
    "<p>File ID: <b>$id</b><br>";
    print 
    "<p>File Name: <b>$form_data_name</b><br>";
    print 
    "<p>File Size: <b>$form_data_size</b><br>";
    print 
    "<p>File Type: <b>$form_data_type</b><p>";
    print 
    "To upload another file <a href=http://www.stuff4yoursite.org/file> Click Here</a>";
    ?>

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Like mentioned by nikkiH put in mysql_error() for debugging:
    PHP Code:
    $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ""VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')") or die(mysql_error()); 
    Good luck;

  • #5
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Show.php code
    Quote Originally Posted by googleit View Post
    i

    PHP Code:
    <?php
    mysql_connect
    ("host""username""pw");
    mysql_select_db("db_name");
    $query "SELECT data,filetype FROM uploads where id=$id";
    $result MYSQL_QUERY($query);
    $data MYSQL_RESULT($result,0,"data");
    $type MYSQL_RESULT($result,0,"filetype");
    Header"Content-type: $type");
    print 
    $data;
    ?>
    Got this error but this is where i upload (this works fine) the other code is for show.php where it shows the data from db

    Code:
    Warning: fread(): supplied argument is not a valid stream resource in  /home/content/b/r/a/bradleyhession/html/test/upload.php on line 4

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Documentation:
    http://us3.php.net/mysql_query
    Return Values
    For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error.

    Ok, try this and let us know what you get.

    Code:
    <?php
    mysql_connect("host", "username", "pw") or die(mysql_error());
    mysql_select_db("db_name") or die(mysql_error());
    $query = "SELECT data,filetype FROM uploads where id=$id";
    $result = MYSQL_QUERY($query);
    
    if (!$result) {
       die('Invalid query: ' . mysql_error());
    }
    
    $data = MYSQL_RESULT($result,0,"data");
    $type = MYSQL_RESULT($result,0,"filetype");
    Header( "Content-type: $type");
    print $data;
    ?>
    Why, yes, it has been awhile since I've coded PHP.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    got this..
    Code:
    Invalid query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    my sql syntax is
    Code:
     CREATE TABLE data (name VARCHAR(30), email VARCHAR(30), location VARCHAR(30));
    Code:
    CREATE TABLE uploads (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, description CHAR(50), data LONGBLOB, filename CHAR(50), filesize CHAR(50), filetype CHAR(50) );
    Last edited by googleit; 12-03-2006 at 12:44 PM.

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    "id" is reserved in SQL Server, so it might be in MySQL too.
    It's always a good idea to use brackets in SQL Server, and backquotes in MySQL for field names, just in case you're hitting a reserved word.

    Try this.

    Code:
    CREATE TABLE data (`name` VARCHAR(30), `email` VARCHAR(30), `location` VARCHAR(30));
    Code:
    CREATE TABLE uploads (`id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, `description` CHAR(50), `data` LONGBLOB, `filename` CHAR(50), `filesize` CHAR(50), `filetype` CHAR(50) );

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've been trying this on my own and it still doesn't work. perhaps i should just hire someone like a freelance to do it for me?

  • #10
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That depends on how much you're willing to pay for the time you save. How much is your time worth?

    Not a lot of freelancers just debug stuff for people on an hourly basis, though. You have to give them your usernames, passwords, and all that so they can set things up, so be sure to get references.
    They can't debug it for you without having access to all of the relevant code and servers.

    That said, did you get another error?

    If you can get to the phpMyAdmin tool, create the statements in there and just copy/paste it into your php. The hard-ish part is escaping quotes and stuff, but if you can get it to run in phpMyAdmin, you know the SQL is correct and have only to properly form the PHP.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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