Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: FPDF module

  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts

    FPDF module

    Good day,

    I'm still a beginner at PHP. This is the first time that I am attempting to use the fpdf function / module

    I have downloaded fpdf.zip and extracted it into php www folder.
    I included fpdf.php as well as used require fpdf.php.

    I now receive two error messages:

    Notice: Constant FPDF_VERSION already defined in C:\Program Files\EasyPHP-5.3.3\www\fpdf.php on line 10

    Fatal error: Cannot redeclare class FPDF in C:\Program Files\EasyPHP-5.3.3\www\fpdf.php on line 13

    Please assist.

    List.php

    PHP Code:
    <?php

        
    include "connect.php";
        include 
    "fpdf.php";
        
    ?>    

    <body>

                <form method="post" action="list.php" name="report1">
                <table align='center'><tr><td><input type="submit" name="report1" value="Print Report">
                </table><br>
                
    <?php    

    if(isset($_REQUEST['report1']))
        {
        
        require (
    'fpdf.php');
        
        
    $pdf=new PDF();
        
    $pdf->Open();
        
        
    $connection connect_server_db();
        
        echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td><td colspan='2'>Action</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td><td>";
        echo 
    "</tr>";
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
        
        
    $pdf->Output();
        }
        
    ?>

    Downloaded fpdf.php

    PHP Code:
    <?php
    /*******************************************************************************
    * FPDF                                                                         *
    *                                                                              *
    * Version: 1.6                                                                 *
    * Date:    2008-08-03                                                          *
    * Author:  Olivier PLATHEY                                                     *
    *******************************************************************************/

    define('FPDF_VERSION','1.6');

    class 
    FPDF
    {
    var 
    $page;               //current page number
    var $n;                  //current object number
    var $offsets;            //array of object offsets
    var $buffer;             //buffer holding in-memory PDF
    var $pages;              //array containing pages
    var $state;              //current document state
    var $compress;           //compression flag
    var $k;                  //scale factor (number of points in user unit)
    var $DefOrientation;     //default orientation
    var $CurOrientation;     //current orientation
    var $PageFormats;        //available page formats
    var $DefPageFormat;      //default page format
    var $CurPageFormat;      //current page format
    var $PageSizes;          //array storing non-default page sizes
    var $wPt,$hPt;           //dimensions of current page in points
    var $w,$h;               //dimensions of current page in user unit
    var $lMargin;            //left margin
    var $tMargin;            //top margin
    var $rMargin;            //right margin
    var $bMargin;            //page break margin
    var $cMargin;            //cell margin
    var $x,$y;               //current position in user unit
    var $lasth;              //height of last printed cell
    var $LineWidth;          //line width in user unit
    var $CoreFonts;          //array of standard font names
    var $fonts;              //array of used fonts
    var $FontFiles;          //array of font files
    var $diffs;              //array of encoding differences
    var $FontFamily;         //current font family
    var $FontStyle;          //current font style
    var $underline;          //underlining flag
    var $CurrentFont;        //current font info
    var $FontSizePt;         //current font size in points
    var $FontSize;           //current font size in user unit
    var $DrawColor;          //commands for drawing color
    var $FillColor;          //commands for filling color
    var $TextColor;          //commands for text color
    var $ColorFlag;          //indicates whether fill and text colors are different
    var $ws;                 //word spacing
    var $images;             //array of used images
    var $PageLinks;          //array of links in pages
    var $links;              //array of internal links
    var $AutoPageBreak;      //automatic page breaking
    var $PageBreakTrigger;   //threshold used to trigger page breaks
    var $InHeader;           //flag set when processing header
    var $InFooter;           //flag set when processing footer
    var $ZoomMode;           //zoom display mode
    var $LayoutMode;         //layout display mode
    var $title;              //title
    var $subject;            //subject
    var $author;             //author
    var $keywords;           //keywords
    var $creator;            //creator
    var $AliasNbPages;       //alias for total number of pages
    var $PDFVersion;         //PDF version number

    /*******************************************************************************
    *                                                                              *
    *                               Public methods                                 *
    *                                                                              *
    *******************************************************************************/
    function FPDF($orientation='P'$unit='mm'$format='A4')
    {
        
    //Some checks
        
    $this->_dochecks();
        
    //Initialization of properties
        
    $this->page=0;
        
    $this->n=2;
        
    $this->buffer='';
        
    $this->pages=array();
        
    $this->PageSizes=array();
        
    $this->state=0;
        
    $this->fonts=array();
        
    $this->FontFiles=array();
        
    $this->diffs=array();
        
    $this->images=array();
        
    $this->links=array();
        
    $this->InHeader=false;
        
    $this->InFooter=false;
        
    $this->lasth=0;
        
    $this->FontFamily='';
        
    $this->FontStyle='';
        
    $this->FontSizePt=12;
        
    $this->underline=false;
        
    $this->DrawColor='0 G';
        
    $this->FillColor='0 g';
        
    $this->TextColor='0 g';
        
    $this->ColorFlag=false;
        
    $this->ws=0;
        
    //Standard fonts
        
    $this->CoreFonts=array('courier'=>'Courier''courierB'=>'Courier-Bold''courierI'=>'Courier-Oblique''courierBI'=>'Courier-BoldOblique',
            
    'helvetica'=>'Helvetica''helveticaB'=>'Helvetica-Bold''helveticaI'=>'Helvetica-Oblique''helveticaBI'=>'Helvetica-BoldOblique',
            
    'times'=>'Times-Roman''timesB'=>'Times-Bold''timesI'=>'Times-Italic''timesBI'=>'Times-BoldItalic',
            
    'symbol'=>'Symbol''zapfdingbats'=>'ZapfDingbats');
    Last edited by schalk1807; 10-16-2013 at 08:46 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 546 Times in 545 Posts
    This line:
    PHP Code:
    include "fpdf.php"
    brings your fpdf file into the script and it defines a class.

    You then have this line:
    PHP Code:
    require ('fpdf.php'); 
    which does it all over again and generates your error. Remove that line.
    Evolution - The non-random survival of random variants.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thank you for the quick reply.

    I tried that Sunfighter, then I get this:

    Fatal error: Class 'PDF' not found in C:\Program Files\EasyPHP-5.3.3\www\list.php on line 129

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,762
    Thanks
    23
    Thanked 546 Times in 545 Posts
    Sounds like a different problem. I don't have 129 lines of code for list.php.

    But just to be sure Move the include "connect.php"; include "fpdf.php"; from the top php into the bottom php and delete the top php. so things look like this:
    PHP Code:
    <body>
    <form method="post" action="list.php" name="report1">
    <table align='center'><tr><td><input type="submit" name="report1" value="Print Report">
    </table><br>
    <?php
    if(isset($_REQUEST['report1'])){
        include 
    "connect.php";
        include 
    "fpdf.php";

        
    $pdf=new PDF();
        
    $pdf->Open();
    Evolution - The non-random survival of random variants.

  • Users who have thanked sunfighter for this post:

    schalk1807 (10-16-2013)

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    152
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by schalk1807 View Post
    Thank you for the quick reply.

    I tried that Sunfighter, then I get this:

    Fatal error: Class 'PDF' not found in C:\Program Files\EasyPHP-5.3.3\www\list.php on line 129
    I don't see line 129 in your list.php above, likely you've made changes since that post so I am making an educated guess here, but the class you want to use is FPDF, not PDF.

  • #6
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanx guys,

    I moved the include as you said Sunfighter, however I need the include "connect.php" to stay at the top.

    I changed $pdf = new PDF to $pdf = new FPDF.

    Now the list is generated not to pdf but straight to the web page, with the following error:

    FPDF error: Some data has already been output, can't send PDF file

    here is the full current list.php

    PHP Code:
    <?PHP
    session_start
    ();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: login.php");
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

    <!-- #BeginTemplate "../master.dwt" -->

    <head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <!-- #BeginEditable "doctitle" -->
    <title>Portfolio - ICT 3714 - Student nr: 40145344</title>
    <!-- #EndEditable -->
    <link href="styles/style1.css" media="screen" rel="stylesheet" title="CSS" type="text/css" />
    <style type="text/css">
    .style1 {
        text-align: center;
    }
    </style>
    </head>

    <?php

        
    include "connect.php";
        
    ?>    

    <?php

    //start of session

    if(!isset($_SESSION)){

    session_start();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: index.php");
    }
    }

    ?>

    <body>

    <!-- Begin Container -->
    <div id="container">
        <!-- Begin Masthead -->
        <div id="masthead">
            <h1 class="style1"><a href="#">Answered Prayers</a></h1>
            <h3>&nbsp;</h3>
        </div>
        <!-- End Masthead -->
        <!-- Begin Navigation -->
        <div id="navigation">
            <ul>
                <li><a href="home.php">Home</a></li>
                <li><a href="register.php">Register</a></li>
                <li><a href="index.php">Login</a></li>
                <li><a href="insert.php">Insert</a></li>
                <li><a href="list.php">List</a></li>
                <li><a href="query.php">Query</a></li>
                <li><a href="logout.php">Logout</a></li>
                <li><a href="help.php">Help</a></li>

            </ul>
        </div>
        <!-- End Navigation -->
        <!-- Begin content_container -->
        <div id="content_container">
            <!-- Begin Left Column -->
            <div id="column_left">
                <!-- #BeginEditable "content" -->
                <h2>Available Stock</h2>
                
                <form method="post" action="list.php" name="report1">
                <table align='center'><tr><td><input type="submit" name="report1" value="Print Report">
                </table><br>
                
                    <?php

    $connection 
    connect_server_db();



            echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td><td colspan='2'>Action</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td><td>";
        echo 
    "<a href=edit.php?item_id=".$item_id."&update=yes>Edit</a>";
        echo 
    "</td><td>";
        echo 
    "<a href=delete.php?item_id=".$item_id."&delete1=yes>Delete</a>";
        echo 
    "</tr>";
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
    ?>

    <?php

    if(isset($_REQUEST['report1']))
        {
        
        include 
    "fpdf.php";
        
        
    $pdf=new FPDF();
        
    $pdf->Open();
        
        
    $connection connect_server_db();
        
        echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td>";
        
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
        
        
    $pdf->Output();
        }
        
    ?>    
                
                
                <!-- #EndEditable --></div>
            <!-- End Left Column -->
            <!-- Begin Right Column -->
            <div id="column_right">
                <!-- #BeginEditable "sidebar" -->
                <h4><u>TYPE IDs</u></h4>
                <p><table border='1'>
        <tr><td>1 = Dolls.</td></tr>
        <tr><td>2 = Watches.</td></tr>
        <tr><td>3 = Furniture.</td></tr>
        <tr><td>4 = Glass.</td></tr></table></p></div>
            <!-- End Right Column -->
            <!-- Begin Footer -->
            <div id="footer">
                <div id="copyright">
                    <p>Copyright  2013. All Rights Reserved.</p>
                </div>
                <p><a href="home.php">Home</a> | 
                <a href="register.php">Register</a> | 
                <a href="index.php">Login</a> |
                <a href="insert.php">Insert</a> |
                    <a href="list.php">List</a> |
                    <a href="query.php">Query</a> |

            <a href="logout.php">Logout</a> |

                <a href="help.php">Help</a></p>
            </div>
            <!-- End Footer --></div>
        <!-- End content_container --></div>
    <!-- End Container -->

    </body>

    <!-- #EndTemplate -->

    </html>

  • #7
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    152
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by schalk1807 View Post
    Thanx guys,

    I moved the include as you said Sunfighter, however I need the include "connect.php" to stay at the top.

    I changed $pdf = new PDF to $pdf = new FPDF.

    Now the list is generated not to pdf but straight to the web page, with the following error:

    FPDF error: Some data has already been output, can't send PDF file

    here is the full current list.php

    PHP Code:
    <?PHP
    session_start
    ();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: login.php");
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

    <!-- #BeginTemplate "../master.dwt" -->

    <head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <!-- #BeginEditable "doctitle" -->
    <title>Portfolio - ICT 3714 - Student nr: 40145344</title>
    <!-- #EndEditable -->
    <link href="styles/style1.css" media="screen" rel="stylesheet" title="CSS" type="text/css" />
    <style type="text/css">
    .style1 {
        text-align: center;
    }
    </style>
    </head>

    <?php

        
    include "connect.php";
        
    ?>    

    <?php

    //start of session

    if(!isset($_SESSION)){

    session_start();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: index.php");
    }
    }

    ?>

    <body>

    <!-- Begin Container -->
    <div id="container">
        <!-- Begin Masthead -->
        <div id="masthead">
            <h1 class="style1"><a href="#">Answered Prayers</a></h1>
            <h3>&nbsp;</h3>
        </div>
        <!-- End Masthead -->
        <!-- Begin Navigation -->
        <div id="navigation">
            <ul>
                <li><a href="home.php">Home</a></li>
                <li><a href="register.php">Register</a></li>
                <li><a href="index.php">Login</a></li>
                <li><a href="insert.php">Insert</a></li>
                <li><a href="list.php">List</a></li>
                <li><a href="query.php">Query</a></li>
                <li><a href="logout.php">Logout</a></li>
                <li><a href="help.php">Help</a></li>

            </ul>
        </div>
        <!-- End Navigation -->
        <!-- Begin content_container -->
        <div id="content_container">
            <!-- Begin Left Column -->
            <div id="column_left">
                <!-- #BeginEditable "content" -->
                <h2>Available Stock</h2>
                
                <form method="post" action="list.php" name="report1">
                <table align='center'><tr><td><input type="submit" name="report1" value="Print Report">
                </table><br>
                
                    <?php

    $connection 
    connect_server_db();



            echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td><td colspan='2'>Action</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td><td>";
        echo 
    "<a href=edit.php?item_id=".$item_id."&update=yes>Edit</a>";
        echo 
    "</td><td>";
        echo 
    "<a href=delete.php?item_id=".$item_id."&delete1=yes>Delete</a>";
        echo 
    "</tr>";
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
    ?>

    <?php

    if(isset($_REQUEST['report1']))
        {
        
        include 
    "fpdf.php";
        
        
    $pdf=new FPDF();
        
    $pdf->Open();
        
        
    $connection connect_server_db();
        
        echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td>";
        
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
        
        
    $pdf->Output();
        }
        
    ?>    
                
                
                <!-- #EndEditable --></div>
            <!-- End Left Column -->
            <!-- Begin Right Column -->
            <div id="column_right">
                <!-- #BeginEditable "sidebar" -->
                <h4><u>TYPE IDs</u></h4>
                <p><table border='1'>
        <tr><td>1 = Dolls.</td></tr>
        <tr><td>2 = Watches.</td></tr>
        <tr><td>3 = Furniture.</td></tr>
        <tr><td>4 = Glass.</td></tr></table></p></div>
            <!-- End Right Column -->
            <!-- Begin Footer -->
            <div id="footer">
                <div id="copyright">
                    <p>Copyright  2013. All Rights Reserved.</p>
                </div>
                <p><a href="home.php">Home</a> | 
                <a href="register.php">Register</a> | 
                <a href="index.php">Login</a> |
                <a href="insert.php">Insert</a> |
                    <a href="list.php">List</a> |
                    <a href="query.php">Query</a> |

            <a href="logout.php">Logout</a> |

                <a href="help.php">Help</a></p>
            </div>
            <!-- End Footer --></div>
        <!-- End content_container --></div>
    <!-- End Container -->

    </body>

    <!-- #EndTemplate -->

    </html>
    You have to decide whether the URL to this document is going to return a PDF file (to download) or an HTML file (to display).

    You start with the HTML, then you generate a PDF and try to output it and it's too late. You can't do both, have to do one or the other.

  • #8
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thank you for your patience Daniel,

    Let me explain what I need to accomplish. The list link opens The list page which automatically displays a list of all items from the database.

    Now I want to include a "Print Report" button to the page, which has to output the list to a pdf.

    I moved the whole if (isset($_REQUEST['report1'])) { part to a connect.php page, which contains no HTML and it is still giving the same error message.

    I'm sorry, but I'm truly lost.

  • #9
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    152
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by schalk1807 View Post
    Thank you for your patience Daniel,

    Let me explain what I need to accomplish. The list link opens The list page which automatically displays a list of all items from the database.

    Now I want to include a "Print Report" button to the page, which has to output the list to a pdf.

    I moved the whole if (isset($_REQUEST['report1'])) { part to a connect.php page, which contains no HTML and it is still giving the same error message.

    I'm sorry, but I'm truly lost.
    First, You'd have to post the code for that page for us to see in order to help you.

    Second, unless you changed the list code again, you're loading the connect.php page right into this page (again, after some HTML), so naturally you get the same error.

    You'll have to post the latest version of both files.
    Last edited by Daniel Israel; 10-15-2013 at 07:24 PM.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Are you creating a PDF or are you using HTML? You can't use both in the same page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I moved all back to list.php and placed it after the </html> to see if it will work.

    It did not.

    @Felgall, it is an HTML page which displays a list of the items in the database. Now I am trying to output it to a PDF for printing.

    This will now be very long winded, but I will post the whole of the List.php file.

    All the code involved is on the list.php page. (Moving it to the connect.php page didn't work. I do understand when you all explain that pdf and html cannot be used together, but how else to do it?

    PHP Code:
    <?PHP
    session_start
    ();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: login.php");
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

    <!-- #BeginTemplate "../master.dwt" -->

    <head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <!-- #BeginEditable "doctitle" -->
    <title>Portfolio - ICT 3714 - Student nr: 40145344</title>
    <!-- #EndEditable -->
    <link href="styles/style1.css" media="screen" rel="stylesheet" title="CSS" type="text/css" />
    <style type="text/css">
    .style1 {
        text-align: center;
    }
    </style>
    </head>

    <?php

        
    include "connect.php";
            
    ?>    

    <?php

    //start of session

    if(!isset($_SESSION)){

    session_start();
    if (!(isset(
    $_SESSION['login']) && $_SESSION['login'] != '')) {
        
    header ("Location: index.php");
    }
    }

    ?>

    <body>

    <!-- Begin Container -->
    <div id="container">
        <!-- Begin Masthead -->
        <div id="masthead">
            <h1 class="style1"><a href="#">Answered Prayers</a></h1>
            <h3>&nbsp;</h3>
        </div>
        <!-- End Masthead -->
        <!-- Begin Navigation -->
        <div id="navigation">
            <ul>
                <li><a href="home.php">Home</a></li>
                <li><a href="register.php">Register</a></li>
                <li><a href="index.php">Login</a></li>
                <li><a href="insert.php">Insert</a></li>
                <li><a href="list.php">List</a></li>
                <li><a href="query.php">Query</a></li>
                <li><a href="logout.php">Logout</a></li>
                <li><a href="help.php">Help</a></li>

            </ul>
        </div>
        <!-- End Navigation -->
        <!-- Begin content_container -->
        <div id="content_container">
            <!-- Begin Left Column -->
            <div id="column_left">
                <!-- #BeginEditable "content" -->
                <h2>Available Stock</h2>
                
                <form method="post" action="connect.php" name="report1">
                <table align='center'><tr><td><input type="submit" name="report1" value="Print Report">
                </table><br>
                
                    <?php

    $connection 
    connect_server_db();



            echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td><td colspan='2'>Action</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td><td>";
        echo 
    "<a href=edit.php?item_id=".$item_id."&update=yes>Edit</a>";
        echo 
    "</td><td>";
        echo 
    "<a href=delete.php?item_id=".$item_id."&delete1=yes>Delete</a>";
        echo 
    "</tr>";
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
    ?>

            
                
                <!-- #EndEditable --></div>
            <!-- End Left Column -->
            <!-- Begin Right Column -->
            <div id="column_right">
                <!-- #BeginEditable "sidebar" -->
                <h4><u>TYPE IDs</u></h4>
                <p><table border='1'>
        <tr><td>1 = Dolls.</td></tr>
        <tr><td>2 = Watches.</td></tr>
        <tr><td>3 = Furniture.</td></tr>
        <tr><td>4 = Glass.</td></tr></table></p></div>
            <!-- End Right Column -->
            <!-- Begin Footer -->
            <div id="footer">
                <div id="copyright">
                    <p>Copyright  2013. All Rights Reserved.</p>
                </div>
                <p><a href="home.php">Home</a> | 
                <a href="register.php">Register</a> | 
                <a href="index.php">Login</a> |
                <a href="insert.php">Insert</a> |
                    <a href="list.php">List</a> |
                    <a href="query.php">Query</a> |

            <a href="logout.php">Logout</a> |

                <a href="help.php">Help</a></p>
            </div>
            <!-- End Footer --></div>
        <!-- End content_container --></div>
    <!-- End Container -->

    </body>

    <!-- #EndTemplate -->

    </html>

    <?php

    if(isset($_REQUEST['report1']))
        {
        include 
    "fpdf.php";
        
        
    $pdf=new FPDF();
        
    $pdf->Open();
        
        
    $connection connect_server_db();
        
        echo 
    "<table border = '1' align=center><tr bgcolor='#0099ff' align='center'><td>Item ID</td><td>Type ID</td>
    <td>Item Name</td></tr>"
    ;
                
                    
    $query "SELECT * FROM items ORDER BY item_id";
                    
                    
    $result mysql_query($query)
                    or die(
    "Query failed: " mysql_error());
                    
        while(
    $row mysql_fetch_array($result)) 
        {
        
    $item_id=$row['item_id'];
        
        echo 
    "<tr><td>";
        echo 
    $row['item_id'];
        echo 
    "</td><td>";
        echo 
    $row['type_id'];
        echo 
    "</td><td>";
        echo 
    $row['item_name'];
        echo 
    "</td>";
        
        }
        
        echo 
    "</table>";
        
        
    //closing database    
        
        
    mysql_close(connect_server_db('$connection'));
        
        
    $pdf->Output();
        }
        
    ?>

  • #12
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    152
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by schalk1807 View Post
    All the code involved is on the list.php page. (Moving it to the connect.php page didn't work. I do understand when you all explain that pdf and html cannot be used together, but how else to do it?

    You can't output HTML and PDF on the same page. Which means you have to have one file that displays the HTML page and another file that displays the PDF. And you can't include them in each other.

    Currently, when you hit the submit button, it loads connect.php, which you didn't include the latest version. That file should generate the PDF (and do nothing else). Problem is, you're already including the connect.php in this file. I would suggest creating a new file with just the PDF generator and call that.

  • #13
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    If you are going to include both HTML and PDF in the same file then you need to pass a value to that file that tells it which of the two it is outputting this time.

    Until you have a greater knowledge of PHP it will be much simpler to keep them completely separate - one PHP file that creates an HTML web page and a second that creates a PDF.

    When creating a PDF the page is not allowed to output anything at all before it generates the PDF.
    Last edited by felgall; 10-16-2013 at 02:57 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    schalk1807 (10-16-2013)

  • #14
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thank you Daniel and felgall,

    If I understand you correctly: I simply cannot call the FPDF function from a page which has already outputted HTML, and the list.php page immediately outputs HTML when it opens.

    Now my dilemma is: how can I let the user print a report of the list? I need the "Print Report" button to appear on the list.php page.
    Last edited by schalk1807; 10-16-2013 at 11:23 AM.

  • #15
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    another possible option for you, I have never used it on windows but I use wkhtmltopdf to create PDF's, basically you save your file as a html file and call wkhtmltopdf to convert it for you.

    I use it to generate invoices, barcodes for label printing etc and have found it far easier than any of the PDF libraries out there though its possible I was not trying hard enough
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    schalk1807 (10-16-2013)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •