无法使用php和mysql将数据从HTML表单解析为PDF

时间:2011-06-10 15:44:06

标签: php mysql pdf

我处于这样一种情况:我需要在HTML表单上提交时传输数据以在MYSQL数据库中更新,并为提交的数据生成pdf。这还必须包含增量值,如生成收据编号。

我的pdf代码在这里用php编写。

<?php

require('fpdf.php');

    class PDF extends FPDF
{
//Page header
function Header()
{

    //Move to the right
    $this->Cell(130);
    //Title
    include('connection.php');
    mysql_select_db("inventory") or die("Couldn't find db");
    $data = mysql_query("SELECT * FROM sold WHERE imei = '6135352313'");//This is where i need help how to get data from the HTML form after updating in MYSQL
    while ($result1 = mysql_fetch_assoc($data))
{

    $this->Cell(50,10,'CP '.$result1["receiptnumber"],1,1,'C'); //receipt number to be pulled from Auto_increment field in database
    }
    //Move to the right
    $this->Cell(130);
    //Date
    $this->Cell(50,10,date("l F dS Y "),1,0,'C');
    //Line break
    $this->Ln(20);
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
    include('connection.php');
    mysql_select_db("inventory") or die("Couldn't find db");
    $data = mysql_query("SELECT * FROM sold WHERE imei = '6135352313'"); //This is where i need help how to get data from the HTML form after updating in MYSQL

    while ($result = mysql_fetch_assoc($data))
{

    //Move to the right
    $pdf->Cell(50,5,'Invoice To ',0,0,'R');
    $pdf->SetFont('Arial','B',15);
    $pdf->Cell(140,8,$result["firstname"]." ".$result["lastname"],1,1,'C');
    $pdf->SetFont('Arial','B',10);

    }
$pdf->Output();
?>

1 个答案:

答案 0 :(得分:0)

您可以将数据添加到SQL查询中,如下所示:

$imei = mysql_real_escape_string($_POST['imei']);
$data = mysql_query("SELECT * FROM sold WHERE imei = '$imei'");

请勿忘记使用mysql_real_escape_string()从用户处获取字符串 另外,请不要忘记使用单引号'在查询中包围$ var,如图所示。 (这对于保护您的代码至关重要)

如果您以任何其他方式使用mysql_query,您将容易受到SQL-injection攻击。