0

I have this PHP code that creates a QR code with the given data:

<?php

   include(JPATH_LIBRARIES . '/phpqrcode/qrlib.php');

   $tempDir = JPATH_SITE . '/images/';   
   $codeContents = 'This Goes From File';
   $fileName     = 'qr_'.md5($codeContents).'.png';

   $pngAbsoluteFilePath = $tempDir.$fileName;
   $urlRelativeFilePath = JUri::root() .'images/' . $fileName;

   if (!file_exists($pngAbsoluteFilePath)) {
      QRcode::png($codeContents, $pngAbsoluteFilePath);
   }
   else {
      echo "Not working!";
   }

   echo '<img src="'.$urlRelativeFilePath.'" />';

?>

What we need is to connect to a MySQL table (#__rsforms_submissions), retrieve some fields (for example, Name and Mail, Phone) and insert them in the QR code instead of the data provided by the example. To do so I would retrieve the logged in user's user

$user = JFactory::getUser();
$username = JUserHelper::getUsername($user->id);

Then, the MySQL query would look something like

SELECT Name,Mail, Phone FROM #__rsforms_submissions WHERE Username = $username

However, what's next? How do I insert these values into the PHP code? Thanks!

Dani

2
Contributors
1
Reply
9
Views
2 Years
Discussion Span
Last Post by almostbob
0
<?php
   include(JPATH_LIBRARIES . '/phpqrcode/qrlib.php');
   $data = mysql_fetch_array( mysql_query("SELECT Name, Mail, Phone FROM #_rsforms_submissions WHERE Username = $username"));
   $tempDir = JPATH_SITE . '/images/';   
   $codeContents = $data['name']." ".$data['phone']." ".$data['mail'];
   $fileName = 'qr_'.md5($codeContents).'.png';
   $pngAbsoluteFilePath = $tempDir.$fileName;
   $urlRelativeFilePath = JUri::root() .'images/' . $fileName;
   if (!file_exists($pngAbsoluteFilePath)) {
      QRcode::png($codeContents, $pngAbsoluteFilePath);
   }
   else {
      echo "Not working!";
   }
   echo '<img src="'.$urlRelativeFilePath.'" />';
?>

This is lousy code, its late at night, may need cleaning up, its a start point

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.