Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Cant Seem to a page to display at all


[SOLVED] Cant Seem to a page to display at all

Reply
  #1 (permalink)  
Old 07-08-08, 09:20 AM
jetstrike jetstrike is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Cant Seem to a page to display at all

downoload.php
Code:
<?
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.
Reply With Quote
  #2 (permalink)  
Old 07-08-08, 10:17 AM
Dissonance Dissonance is offline
Newbie Coder
 
Join Date: Jul 2008
Location: Kentucky, USA
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Do you have shorttags enabled in your php.ini file?

At a glance, it all looks correct, but I've got 4 hours of sleep and I might have missed something.

Edit: Also, do you have errors turned on? As not having them enabled would give you a blank page when an error occurs.

PHP Code:

error_reporting(E_ALL);
ini_set('display_errors''1'); 

Last edited by Dissonance; 07-08-08 at 10:21 AM.
Reply With Quote
  #3 (permalink)  
Old 07-08-08, 06:24 PM
dustin56 dustin56 is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
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.

Last edited by dustin56; 07-08-08 at 06:28 PM.
Reply With Quote
  #4 (permalink)  
Old 07-09-08, 02:42 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:
Originally Posted by dustin56 View Post
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.
This is not true. It'll return false, and no errors/warnings are thrown. It's still a good idea to check if the row existed, though.

And don't forget to filter the user input: www.php.net/intval
Reply With Quote
  #5 (permalink)  
Old 07-09-08, 08:45 PM
dustin56 dustin56 is offline
Newbie Coder
 
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I stand corrected.
Reply With Quote
  #6 (permalink)  
Old 07-10-08, 11:05 AM
jetstrike jetstrike is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Dissonance View Post
Do you have shorttags enabled in your php.ini file?

At a glance, it all looks correct, but I've got 4 hours of sleep and I might have missed something.

Edit: Also, do you have errors turned on? As not having them enabled would give you a blank page when an error occurs.

PHP Code:

error_reporting(E_ALL);

ini_set('display_errors''1'); 
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.
Reply With Quote
  #7 (permalink)  
Old 07-10-08, 11:11 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You didn't answer the PHP short open tags question, but my guess is that they're disabled.

Replace all <? by <?php , and all <?= by <?php echo.
Reply With Quote
  #8 (permalink)  
Old 07-10-08, 11:51 AM
jetstrike jetstrike is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Here is my new download.php
Code:
<?
error_reporting(E_ALL);
ini_set('display_errors', '1');  

if(isset($_GET['id']))
{
	include 'config.php';
	include 'opendb.php';

	$id      = $_GET['id'];
	$query   = "SELECT name, type, size, content, characters, scripture, date, title FROM upload WHERE id = '$id'";
	$result  = mysql_query($query) or die('Error, query failed');
	list($name, $type, $size, $content, $characters, $scripture, $date, $title) = 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))
	{
?>
	<table cols="4" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">';
	<tr><th>Title</th><th>Chatacters</th><th>Scripture</th><th>Date</th></tr>
	<tr><td><a href="download.php?id=<?=$id;?>"><?=$name;?>><?$title?></a></td><td><?$characters?></td><td><?$scripture?></td><td>$date</td></tr>
	</table>
<?		
	}
}
include 'closedb.php';
?>
</body>
</html>
When I goto the page
http://www.jetstrikewebdesign.com/do...s/download.php
I see this
Code:
';
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.
Reply With Quote
  #9 (permalink)  
Old 07-10-08, 12:12 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Okay, short tags seem to work, but there are a few times where you forgot the equal sign, which tells PHP to output the variable.

PHP Code:

<?$title?>

... should be:
PHP Code:

<?=$title?>
// Or <?php echo $title?>
Reply With Quote
  #10 (permalink)  
Old 07-11-08, 01:33 AM
jetstrike jetstrike is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
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.

PHP Code:

<?

error_reporting
(E_ALL);
ini_set('display_errors''1');  

$characters='';
$scripture='';
$date='';
$title='';

if(isset(
$_GET['id']))
{
    include 
'config.php';
    include 
'opendb.php';

    
$id      $_GET['id'];
    
$query   "SELECT name, type, size, content, characters, scripture, date, title FROM upload WHERE id = '$id'";
    
$result  mysql_query($query) or die('Error, query failed');
    list(
$name$type$size$content$characters$scripture$date$title) = 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))
    {
?>
    <table cols="4" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">';
    <tr><th>Title</th><th>Chatacters</th><th>Scripture</th><th>Date</th></tr>
    <tr><td><a href="download.php?id=<?=$id;?>"><?=$title?></a></td><td><?=$characters?></td><td><?=$scripture?></td><td><?=$date?></td></tr>
    </table>
<?        
    
}
}
include 
'closedb.php';
?>
</body>
</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[turnkey] Lyrics site - $149 (LEGAL) rightinpoint General Advertisements 0 10-22-06 04:33 AM
retreived data and display data upon choice from first page? benq PHP 0 05-06-06 05:45 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.