Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PDF Labels using PHP

Posted on 2009-04-09
1
Medium Priority
?
583 Views
Last Modified: 2013-12-13
Hello,

I am not an expert at PHP or MYSQL, but I have been able to piece together a PHP script to create a sheet of labels from a customer database.  I keep getting an error.


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\labels.php on line 20

Warning: Cannot modify header information - headers already sent by (output started at F:\xampp\htdocs\PDF_label.php:182) in F:\xampp\htdocs\fpdf.php on line 1022
FPDF error: Some data has already been output to browser, can't send PDF file

Here is the Labels.php file.
Labels.php
 
<?php
 
if(!empty($_POST['labels']))
{
 
define('FPDF_FONTPATH','font/');
require_once('PDF_Label.php');
require('conn.php');
$labels = explode(',', $_POST['labels']);
 
$pdf = new PDF_Label('L7163', 'mm', 1, 2);
$pdf->Open();
$pdf->AddPage();
 
foreach($labels as $labelId)
{
$query = "SELECT CustomerID,FirstName,LastName,PhysAddress1,PhysAddress2,PhysTown,PhysState,PhysZip FROM customers
WHERE WSHave = 'ON'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
 
for($i=1;$i<=40;$i++)
$pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s, %s, %s", $row['FirstName'], $row['LastName'], $row['PhysAddress1'], $row['PhysAddress2'], $row['PhysTown'], $row['PhysState'],$row['PhysZip'] ));
 
}
$pdf->Output();
 
}
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
List ids separated by a comma: <input type="text" name="labels" /><br>
<input type="submit" value="Generate Labels" />
</form>

Open in new window

0
Comment
Question by:hydrazi
1 Comment
 
LVL 14

Accepted Solution

by:
shobinsun earned 2000 total points
ID: 24113390
Hello,

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in F:\xampp\htdocs\labels.php on line 20"

Means that your sql query is not correct. Check the table fields. and use 'echo mysql_num_rows($result)' after the line:

$result = mysql_query($query);

You will get the exact number of rows.

Check that.

And for  labels in pdf using FPDF, I have given a good example about that in:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_24292268.html?cid=236#a24060272

Hope this will help you.

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

Means that there is another output is generated before pdf output.

Please check that also.

Regards.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question