0

I want to save QR code image into my database and retrieve it afterwards by calling an sql select statement on it and viewing on a table in my html page. I know to call the SQL statement, I just want to know whether is possible to do this.

<?php
header("Content-type: image/png");
require_once ('vendor/autoload.php');

    enter code here


      try{

        $itemName = $_POST['item'];
        $itemDesc = $_POST['description'];
        $itemPrice = $_POST['price'];
        $itemQuantity = $_POST['quantity'];
        $itemExpiry = $_POST['expiry'];
        $itemCat = $_POST['categoryChoice'];
        $itemOffers = $_POST['offers'];




      } catch(Exception $e){
        die($e->getMessage());
      }




    /*$itemData=$list->posteddata($posts = array($_POST['item'],$_POST['description'],
    $_POST['price'],$_POST['quantity'],$_POST['expiry'],$_POST['categoryChoice'],$_POST['offers']));*/

    $size = isset($_POST['size']) ? (int)$_POST['size'] : 300;
    $padding = isset($_POST['padding']) ? (int)$_POST['padding'] : 10;

$code = ($itemName . $itemDesc . $itemPrice . $itemQuantity . 
$itemExpiry . $itemOffers . $itemCat);
$qr = new Endroid\QrCode\QrCode();
$qr->setText($code);
$qr->setSize($size);
$qr->setPadding($padding);
$qr->render();
?>
2
  • It is possible. What's your problem? Commented Mar 23, 2015 at 12:14
  • I can't get the QR code to save after rending on another page. Commented Mar 23, 2015 at 13:02

1 Answer 1

0

It is possible to store a QR code in your database, to do it you will have to store the file path in your database and then retrieve it.

Alternatively you could store it as an ASCII, for more information on this you can see this answer where @Pawel J. Wal has given an example:

How do I store the qrcode generated using phpqrcode into a db instead of in a filepath?

You can then display it in the html - see this example for more info: PHP display images from database

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, thanks for your reply. The QR code is generated using a form submission. I want to save the QR code first in a directory and then call the FilePath to that QR code image.
Can't you save the contents of $qr to a directory? What does $qr have in it prior to outputting to the screen?
The $qr contains the contents, the size of the QR and the padding.
Never mind I've managed to save it QR code as a png file in a directory. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.