Solved

PDF Labels using PHP

Posted on 2009-04-09
1
561 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
shobinsun earned 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to remove  "0":  in a json string 4 46
CMD R or Page Refresh Resending Update Query Data from Form 8 48
Code not executing correctly. 3 44
phpmyadmin memory error 55 96
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
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 dynamically set the form action using jQuery.

752 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