2014-10-06 55 views
-1

我有這樣的代碼,其輸出的QR碼:我重裝了QR代碼的網頁時,出現錯誤

<?php 
include(JPATH_LIBRARIES . '/phpqrcode/qrlib.php'); 
$db = JFactory::getDbo(); 
$user = JFactory::getUser(); 
$query = $db->getQuery(true); 
$query->select($db->quoteName(array('Soci', 'Nom', 'Cognoms', 'eCorreu'))) 
->from($db->quoteName('#__rsform_socis')) 
->where($db->quoteName('username') . ' = '. $db->quote($user->username)); 
$db->setQuery($query); 
$codeContents = $db->loadObjectList(); 
$data .= "Soci Nº: {$codeContents[0]->Soci}\n "; 
$data .= "Nom: {$codeContents[0]->Nom} "; 
$data .= "{$codeContents[0]->Cognoms}\n"; 
$data .= "e-correu: {$codeContents[0]->eCorreu}"; 
$tempDir = JPATH_SITE . '/images/'; 
$fileName = 'qr_'.md5($data).'.png'; 
$pngAbsoluteFilePath = $tempDir.$fileName; 
$urlRelativeFilePath = JUri::root() .'images/' . $fileName; 
if (!file_exists($pngAbsoluteFilePath)) { 
QRcode::png($data, $pngAbsoluteFilePath); 
} 
echo '<img src="'.$urlRelativeFilePath.'" />'; 
echo '<br><a href="'.$urlRelativeFilePath.'" download="qrcode.png">Descarrega el carnet</a>'; 
?> 

然而,當用戶重新加載頁面或返回到它,它給出了一個錯誤:

Notice: Undefined variable: data in /home/u916662558/public_html/plugins/system/sourcerer/helper.php(632) : runtime-created function on line 3 

我想這與代碼已經在文件系統中的事實有關。我怎樣才能擺脫它(錯誤)? 謝謝,

達尼

+0

'$ data'的第一次出現應該使用賦值而不是串聯:'$ data /*.*/=「SociNº:{$ codeContents [0] - > Soci} \ n」;' – mudasobwa 2014-10-06 14:38:21

回答

1

您沒有在該點定義$data嘗試自我連擊:

$data .= "Soci Nº: {$codeContents[0]->Soci}\n "; 

這是等價功能的

$data = $data . "Soci ..."; 
     ^^^^----not defined yet 

的添加var初始化:

$data = ''; // 
$data .= etc... 
相關問題