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

<?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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.