Why displaying nothing?

This is a discussion on "Why displaying nothing?" within the PHP Forum section. This forum, and the thread "Why displaying nothing? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 28th, 2007, 01:24
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Why displaying nothing?

Hi

I have copied the codes from the book "Build your own Database driven Website" from sitepoint, not sure those codes display nothing while calling it on the browser http://localhost:8888/gallery/index.php? Any inputs and helps will be much appreciated!!

Code: Select all
<?php
    $dbcnx = @mysql_connect('localhost','root','root');
    if(!$dbcnx){
        exit('<p>Unable to connect to the '.'database server at this time.</p>');
    }
if(!@mysql_select_db('photos')){
    exit('<p> Unable to locate the photos '. 'database at this time</p>');
}

if(isset($_GET['action'])){
    $action = $_GET['action'];
}else{ $action = '';

}
if(($action == 'view' or $action == 'gallery') and isset($_GET['id'])){
    $id = $_GET['id'];
    
    //User is retrieving a file
    $sql = "SELECT filename, mimetype, filedata FROM gallery WHERE id='$id'";
    $result= @mysql_query($sql);
    if(!$result){
        exit('Database error: '. mysql_error());
    }
    
    $file = mysql_fetch_array($result);
    if(!$file){ 
    exit('File with given ID not found in database!');
    }
    $filename = $file['filename'];
    $mimetype = $file['mimetype'];
    $filedata = $file['filedata'];
    $description = 'inline';
    
    if($action == 'gallery'){
        $disposition = 'attachment';
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') or strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7')){ 
            $mimetype = 'application/x-download';
        }
    }
    
    header("content-disposition: $disposition; filename=$filename");
    header("content-type: $mimetype");
    header('content-length: '. strlen($filedata));
    
    echo $filedata;
    exit();
}elseif($action == 'del' and isset($_GET['id'])){
    $id = $_GET['id'];
    
    //user is deleting a file
    $sql = "DELETE FROM gallery WHERE id = '$id'";
    $ok = mysql_query($sql);
    if(!$ok){
        exit ('Database error: '. mysql_error());
    }
    
    header('Location: '. $_SERVER['PHP_SELF']);
    exit();
}elseif(isset($_FILES['upload'])){

    //Bail out if the file isn't really an upload
    if(!is_uploaded_file($_FILES['upload'] ['tmp_name'])){
        exit('There was no file uploaded!');
    }
    $uploadfile = $_FILES['upload']['tmp_name'];
    $uploadname = $_FILES['upload']['name'];
    $uploadtype = $_FILES['upload']['type'];
    $uploaddesc = $_POST[['upload']['desc'];
    
    //open file for binary reading ('rb')
    $tempfile = fopen($uploadfile, 'rb');
    
    //read the entire file into memory using PHP's
    //filesize function to get the file size
    $filedata = fread($tempfile, filesize($uploadfile));
    
    //prepare for database insert by adding backslashes
    //before special characters.
    $filedata = addslashes($filedata);
    
    //create the SQL query
    $sql = "INSERT INTO gallery SET filename ='$uploadname', mimetype = '$uploadtype', description ='$uploaddesc', filedata = '$filedata'";
    
    //perform the insert
    $ok = @mysql_query($sql);
    if(!$ok){
        exit('Database error storing file: '. mysql_error());
    }header('Location: '.$_SERVER['PHP_SELF']);
    exit();
}

//Default page view: lists stored files

$sql = 'SELECT id, filename, mimetype, description FROM gallery';
$filelist = @mysql_query($sql);
if(!$filelist){
    exit('Database error '. mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>gallery Repository index</title>
</head>

<body>
<h1>Gallery Repository</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
    <P><label>Upload File:<br /><input type="file" name="upload" /></label></P>
    <p><label>File Description:<br /><input type="text" name="desc" maxlength="255" /></label></p>
    <p><input type="submit" value="Upload" /></p>
</form>
<p>The following files are stored in the database:</p>
<table>
<tr><th>File Name</th><th>Type</th><th>Description</th></tr>
<?php
    if(mysql_num_rows($filelist) > 0){
        while($f = mysql_fetch_array($filelist)){
        ?>
        <tr valign="top">
        <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=view&id=<?php echo $f['id']; ?>"><?php echo $f['filename']; ?></a></td>
        <td><?php echo $f['mimetype']; ?></td>
        <td><?php echo $f['description']; ?></td>
        <td>[<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=gallery&id=<?php echo $f['id']; ?>"> Download</a> | <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=del&id=<?php echo $f['id']; ?>" onclick="return confirm('Delete this file?');">Delete</a> ]</td>
        </tr>
        <?php
            }
        }else{
        ?>
        <tr><td colspan="3"> No Files!</td></tr>
        <?php
        }
?>
</table>
</body>
</html>
Reply With Quote

  #2 (permalink)  
Old Sep 28th, 2007, 10:34
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

So you have PHP and MySQL configured to work on your computer?

If you aren't getting anything then you probably have a fatal PHP error.

Try taking away the error suppression ( the @ symbol) before

@mysql_connect and @mysql_select_db

and check you PHP error log to see what errors you are getting.

I've had a look at the code and can't see any blatent errors.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Sep 28th, 2007, 12:30
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to Voodoochilli
Re: Why displaying nothing?

try commenting out parts of the code which could be causing the problem
Reply With Quote
  #4 (permalink)  
Old Sep 28th, 2007, 12:32
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to Voodoochilli
Re: Why displaying nothing?

also, its probably just me, but for an 'or' condition I use || and for an 'and' condition I use &&, but you probably can do it the way you do.
Reply With Quote
  #5 (permalink)  
Old Sep 28th, 2007, 14:54
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

I had this before
you need to cinfigure you php.ini
if you want i'll send you mine
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Sep 28th, 2007, 17:13
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

Quote:
Originally Posted by alexgeek View Post
I had this before
you need to cinfigure you php.ini
if you want i'll send you mine
I appreciated all you guys comments!!!
Reply With Quote
  #7 (permalink)  
Old Sep 28th, 2007, 17:20
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

Did you want it?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #8 (permalink)  
Old Oct 1st, 2007, 16:48
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

Quote:
Originally Posted by alexgeek View Post
Did you want it?
Yes, sir. Much appreciate!!!
Reply With Quote
  #9 (permalink)  
Old Oct 1st, 2007, 16:51
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

here you go
you need to rename it obviously
Attached Files
File Type: txt php.ini.txt (45.2 KB, 4 views)
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #10 (permalink)  
Old Oct 1st, 2007, 16:54
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

Can I use yours to swap mine php.ini?
Reply With Quote
  #11 (permalink)  
Old Oct 1st, 2007, 16:57
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

yeah that was point
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #12 (permalink)  
Old Oct 1st, 2007, 17:03
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

I saw the maximum upload filesize and post maximum filesize : 2M and 8M in your php.ini, but when I upload 1.1MB mp3, I got this error:
Database error storing file: Got a packet bigger than 'max_allowed_packet' bytes
Reply With Quote
  #13 (permalink)  
Old Oct 1st, 2007, 17:07
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

i think you need twice as much for each download or something
change them to something like 30M and see what happenes
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #14 (permalink)  
Old Oct 1st, 2007, 17:22
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

I have increased them and restarted the apache, mysql. Still got the same problem.

Database error storing file: Got a packet bigger than 'max_allowed_packet' bytes
Reply With Quote
  #15 (permalink)  
Old Oct 1st, 2007, 17:30
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

database error?
are you trying to store a file in a database or something :S
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #16 (permalink)  
Old Oct 1st, 2007, 19:15
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

Yes. I wanted to insert records to store in the database.
Reply With Quote
  #17 (permalink)  
Old Oct 1st, 2007, 19:18
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Why displaying nothing?

you can insert strings and integers but not files.
At least not that i know of
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #18 (permalink)  
Old Oct 1st, 2007, 19:22
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why displaying nothing?

I have inserted records of the small file size without any problems in database, but the file size beyond 2MB.
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code is there...but not displaying... 1840dsgn Web Page Design 3 Aug 16th, 2007 18:28
displaying menus in css kohan Web Page Design 7 Mar 23rd, 2007 22:28
<ul> not displaying the same in FF/IE7? PMicro Web Page Design 10 Mar 21st, 2007 18:49
why is it displaying in IE..?? tameem Web Page Design 3 Oct 14th, 2006 06:09
Need help displaying XML Zhan Web Page Design 5 Aug 19th, 2005 18:47


All times are GMT. The time now is 11:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43