2011-06-10 49 views
0

我需要在HTML表單上提交數據時將數據傳輸到MYSQL數據庫中進行更新,併爲提交的數據生成pdf。這還必須包含增量值,例如生成收據編號。無法使用php和mysql將數據從HTML表單解析爲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(); 
?> 
+0

你的問題是什麼? – 2011-06-10 15:45:32

+0

@ tomalak-geretkal我的問題是從HTML表單中獲取數據以便在mysql中更新爲唯一的標識符並生成帶有唯一標識符的pdf。我能夠做到這一點,只有當我手動給imei一個明確的價值時,imei字段沒有被腳本自己填充。另外,我評論了我需要幫助的領域。 – darsh 2011-06-10 15:48:08

回答

0

你可以得到的數據到您的SQL查詢,像這樣:

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

不要忘了,你逃脫從mysql_real_escape_string()用戶得到的字符串。
另外不要忘記用單引號'包圍查詢中的$ var,如圖所示。 (這是至關重要的,使你的代碼是安全的)

如果以任何其他方式,你會很容易受到攻擊SQL-injection使用mysql_query

+0

非常感謝這幫助,但它有一個錯誤,告訴我注意:未定義的索引:imei在C:\ xampp \ htdocs \ POS \ v2 \ printsale.php在我的代碼中,第19行第一個腳本正在更新數據庫,我需要從相同的IMEI值的數據庫中提取pdf。你能看到如何彌合這個? – darsh 2011-06-10 16:09:33