swatisonee
02-10-2006, 05:36 PM
Hi,
Total newbie question : I found this code PDF.php on www.zend.com .
I ftp it " as is" to the location where all my other php files are. I then added the foll. in another php file which i want to appear as pdf. Clearly i am doing something wrong because it says headers already sent. All my php files have as the first line <? include("variable.php")?> which contains db data etc.
<? include("variable.php")?>
<font face="Tahoma" size="2">
<html> // is this needed ?
<head> // is this needed ?
<meta http-equiv="Content-Type" // is this needed ?
content="text/html; charset=iso-8859-1"> // is this needed ?
<?php
require 'PDF.php'; // Require the lib.
$pdf = &PDF::factory('p', 'a4'); // Set up the pdf object.
$pdf->open(); // Start the document.
$pdf->setCompression(true); // Activate compression.
$pdf->addPage(); // Start a page.
$pdf->setFont('Courier', '', 8); // Set font to arial 8 pt.
$pdf->text(100, 100, 'First page'); // Text at x=100 and y=100.
$pdf->setFontSize(20); // Set font size to 20 pt.
$pdf->text(100, 200, 'loandata.php'); // Text at x=100 and y=200.
$pdf->addPage(); // Add a new page.
$pdf->setFont('Arial', 'BI', 12); // Set font to arial bold italic 12 pt.
$pdf->text(100, 100, 'Second page'); // Text at x=100 and y=200.
$pdf->output('loandata.pdf'); // Output the file named loandata.pdf
?>
</head> // is this needed ?
<?php
$sscid = $_POST["sscid"];
$user = $_POST["user"];
$year = $_POST["year"];
$other = $_POST["other"];
$loan = $_POST["loan"];
$days = $_POST["days"];
$cdate = $_POST["cdate"];
list($cyear, $cmonth, $cday) = explode('-', $cdate);
$cdate1 = $cday."-".$cmonth."-".$cyear ;
?>
<?
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$result = mysql_query("SELECT * FROM `users` WHERE user='user' ");
$myrow = mysql_fetch_array($result);
$first_name = $myrow["firstname"];
$last_name = $myrow["lastname"];
echo $first_name; echo " "; echo $last_name;
<hr>
<p></strong>Loan : Rs.
<strong><?php
echo $loan;
?>
</strong>
Days
: Rs.
<strong>
<?php
echo $days;
?>
</strong> </strong> dated
<strong><?php
echo $cdate1 ;
?>
<?php
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql3 = "UPDATE `Contract` SET `Loan` = $loan , `Days` = $days, `CDate` = '$cdate' WHERE `SSCID` = $sscid";
//echo $sql3;
$result3 = mysql_query($sql3) or die (mysql_error());
?>
</body>
</html>
Could someone guide me on how I should modify the script ? Thanks.
Total newbie question : I found this code PDF.php on www.zend.com .
I ftp it " as is" to the location where all my other php files are. I then added the foll. in another php file which i want to appear as pdf. Clearly i am doing something wrong because it says headers already sent. All my php files have as the first line <? include("variable.php")?> which contains db data etc.
<? include("variable.php")?>
<font face="Tahoma" size="2">
<html> // is this needed ?
<head> // is this needed ?
<meta http-equiv="Content-Type" // is this needed ?
content="text/html; charset=iso-8859-1"> // is this needed ?
<?php
require 'PDF.php'; // Require the lib.
$pdf = &PDF::factory('p', 'a4'); // Set up the pdf object.
$pdf->open(); // Start the document.
$pdf->setCompression(true); // Activate compression.
$pdf->addPage(); // Start a page.
$pdf->setFont('Courier', '', 8); // Set font to arial 8 pt.
$pdf->text(100, 100, 'First page'); // Text at x=100 and y=100.
$pdf->setFontSize(20); // Set font size to 20 pt.
$pdf->text(100, 200, 'loandata.php'); // Text at x=100 and y=200.
$pdf->addPage(); // Add a new page.
$pdf->setFont('Arial', 'BI', 12); // Set font to arial bold italic 12 pt.
$pdf->text(100, 100, 'Second page'); // Text at x=100 and y=200.
$pdf->output('loandata.pdf'); // Output the file named loandata.pdf
?>
</head> // is this needed ?
<?php
$sscid = $_POST["sscid"];
$user = $_POST["user"];
$year = $_POST["year"];
$other = $_POST["other"];
$loan = $_POST["loan"];
$days = $_POST["days"];
$cdate = $_POST["cdate"];
list($cyear, $cmonth, $cday) = explode('-', $cdate);
$cdate1 = $cday."-".$cmonth."-".$cyear ;
?>
<?
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$result = mysql_query("SELECT * FROM `users` WHERE user='user' ");
$myrow = mysql_fetch_array($result);
$first_name = $myrow["firstname"];
$last_name = $myrow["lastname"];
echo $first_name; echo " "; echo $last_name;
<hr>
<p></strong>Loan : Rs.
<strong><?php
echo $loan;
?>
</strong>
Days
: Rs.
<strong>
<?php
echo $days;
?>
</strong> </strong> dated
<strong><?php
echo $cdate1 ;
?>
<?php
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql3 = "UPDATE `Contract` SET `Loan` = $loan , `Days` = $days, `CDate` = '$cdate' WHERE `SSCID` = $sscid";
//echo $sql3;
$result3 = mysql_query($sql3) or die (mysql_error());
?>
</body>
</html>
Could someone guide me on how I should modify the script ? Thanks.