<?
if(isset($_GET['id']))
{
include 'config.php';
include 'opendb.php';
$id = $_GET['id'];
$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-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
include 'closedb.php';
exit;
}
?>
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
include 'config.php';
include 'opendb.php';
$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>
<?
}
}
include 'closedb.php';
?>
</body>
</html>
MySQL Dump
Code:
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 08, 2008 at 09:00 AM
-- Server version: 4.1.22
-- PHP Version: 5.2.6
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `dmill011_upload`
--
-- --------------------------------------------------------
--
-- Table structure for table `upload`
--
CREATE TABLE IF NOT EXISTS `upload` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(30) NOT NULL default '',
`type` varchar(30) NOT NULL default '',
`size` int(11) NOT NULL default '0',
`content` mediumblob NOT NULL,
`characters` varchar(255) NOT NULL default '',
`title` varchar(255) NOT NULL default '',
`date` varchar(255) NOT NULL default '',
`scripture` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
--
-- Dumping data for table `upload`
--
INSERT INTO `upload` (`id`, `name`, `type`, `size`, `content`, `characters`, `title`, `date`, `scripture`) VALUES
(9, 'WHEN HEAVEN COMES DOWN.doc', 'application/msword', 77824, 0xd0cf11e0a1b11ae1000000000000000000000000(theres alot more), 'John', 'What''s So Special About Heaven', 'August 28, 2005', '22:1 - 22:5');
What I want to do is display Title Characters Scripture and Date in a 4 column table I want the title to be a link to download the file however i seem to be stuck with what I have. Any help would be greatly appreciated thank you in advance.
Wow. That's fun. Syntax errors are usually the cause of complete lack of output, but there aren't any. You could try switching to full PHP tags and see if that helps. Perhaps an error in one of the included files? Check them for syntax, or post them here and I will if you like.
Code:
$id = $_GET['id'];
$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);
I noticed that you don't check mysql_num_rows($result) here. If there aren't any rows then mysql_fetch_array($result) will throw an error, and depending on the error level set in php, could result in no output.
I dont have a php.ini file ive never had one nor have I ever needed one atleast not until now apparently... I do have errors turned on but I am not getting an error message.
';
Title Chatacters Scripture Date
WHEN HEAVEN COMES DOWN.doc>
"WHEN HEAVEN COMES DOWN.doc>" Comes through as a link and works to download the file but nothing eelse shows up. I am kinda of stuck on what to do. I do appreciate any help.
Okay I checked all my tags and got a variables undefined error so i defined them all now the dont seem to be getting the information from the database. All of my included files work fine. If I put stuff in for the variables they show up and the link works they just arent getting the information from the database.