leest Posted April 28, 2008 Share Posted April 28, 2008 I have a script that i have previously had working but i have swapped servers and changed some pages and now i can not seem to get this to work, so any ideas would be appreciated. The line to pass the id is: <img src="http://My website/image/download.php?id= echo $site_id the site id is generated from a database query which works ok it then calls this code, i have preset the id and added a couple of echo's to see how far the code gets, but it only displays the first test and doesn't get to the echo id or test2. echo "test"; if(isset($_GET['id'])) { include 'config.php'; $id = 1; echo "$id"; echo "$test2"; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; exit; } Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 This looks like a PHP related problem if you don't get echo id or 'test2' line It looks like your $_GET['id'] variable is not set. Try putting print_r($_GET) right before the IF statement. That will show you what $_GET vars are set and if the $_GET['id'] variable exists and is correct. Quote Link to comment Share on other sites More sharing options...
leest Posted April 28, 2008 Author Share Posted April 28, 2008 Thanks for the reply, because i am calling the download page direct from the browser i manually set the variable as it is of course not being sent one and so i thought i would remove the if statement to see if that made any difference. if(isset($_GET['id'])) { now when i run the script i get no thing at all, Quote Link to comment Share on other sites More sharing options...
leest Posted April 28, 2008 Author Share Posted April 28, 2008 ok i have stripped the code down and took away the query and bottom half of the code so just the variable and echo statements where left and the variable echoed, however as soon as i added the query part the variable stopped echoing. but it doesn't makes sense Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 28, 2008 Share Posted April 28, 2008 That is strange! Ok, so we have confirmed that the if statement is correct and the trouble is somewhere around the 'echo "$id"' or echo "$test2" lines? Have you already defined the variable $test2 that you are echoing with echo "$test2"? Do you have error_reporting set to E_ALL? http://www.phpcodinghelp.com/article.php?article=debug#basic_error_messages Are you manually setting the '$id' variable to '1' for debugging purposes or were you wanting it to be $id = $_GET['id']? Is there anything in 'config.php' that is messing up the script? Is 'config.php' included into your script more then once? Have you checked the SQL query? Does it work correctly by itself? Quote Link to comment Share on other sites More sharing options...
leest Posted April 29, 2008 Author Share Posted April 29, 2008 Ok, Yes i have manually set id to 1 for testing purposes, test2 was an error it wasn't meant to be a variable just an echo to see how far the script got, so that was fixed ages ago. I have checked the config file and that works fine, what i am getting now is an error failed query that is generated by the query it's self and i don't know why. I have included the database structure below. `id` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL, `type` varchar(30) NOT NULL, `size` int(11) NOT NULL, `content` mediumblob NOT NULL, `site_id` varchar(10) NOT NULL, PRIMARY KEY (`id`) below is the script i am now running and the script that generates the error, query failed message. include 'System/connections/db3.php'; $id = 1; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; exit; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.