Solved

PDF Labels using PHP

Posted on 2009-04-09
1
536 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 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 13
how to resize preview image 4 32
html input clean up 3 32
Wordpress Body Class 5 13
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now