...

View Full Version : fileupload help?



googleit
11-29-2006, 08:39 PM
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


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 8this is my 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

nikkiH
11-29-2006, 08:44 PM
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());

googleit
12-01-2006, 03:24 PM
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
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')");
$id= mysql_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>";
?>

Brandoe85
12-01-2006, 03:37 PM
Like mentioned by nikkiH put in mysql_error() for debugging:


$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;

googleit
12-01-2006, 04:02 PM
Show.php code

i


<?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


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

nikkiH
12-02-2006, 02:27 AM
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.


<?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.

googleit
12-03-2006, 11:40 AM
got this..

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 1my sql syntax is

CREATE TABLE data (name VARCHAR(30), email VARCHAR(30), location VARCHAR(30));


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) );

nikkiH
12-04-2006, 02:26 PM
"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.


CREATE TABLE data (`name` VARCHAR(30), `email` VARCHAR(30), `location` VARCHAR(30));


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) );

trainboy72
12-04-2006, 06:12 PM
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?

nikkiH
12-04-2006, 07:15 PM
That depends on how much you're willing to pay for the time you save. How much is your time worth? :D

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum