Jose Jose - 4 years ago 119
PHP Question

Get multiple inputs to QRCode

I have a website that converts the input texts to QRcode. The problem is that I can only get access to the first input text. For example I have this code:

Page1.php

<form action="getForm.php" method="post">

<input type="text" id="text1id" name="Text1"> //I have access
<input type="number" id="text2id" name="text2"> <br><br> //I dont have access
<input type="submit" value="Submit" name="submit_y">
</form>


I only have access to the first "Text1" because I dont know hot to pass two variables to qr code. This is the code of the qrcode

getForm.php

if(isset($_POST['submit_y']))
{
include('phpqrcode/qrlib.php');
$text=$_POST['Text1'];
//I tried to put here the POST of Text2
$folder="images/";
$file_name="qr.png";
$file_name=$folder.$file_name;
QRcode::png($text,$file_name);
echo"<img src='images/qr.png'>";

//To Display Code Without Storing
//QRcode::png($text);
}

Answer Source

Assign variables to each POST array, then use the one from both to form a third variable from the concatenated ones.

if(isset($_POST['submit_y']))
    {
        include('phpqrcode/qrlib.php');
        $text1=$_POST['Text1'];
        $text2=$_POST['text2'];
        $text3 = $text1. "" . $text2; // concatenated from previous 2


        $folder="images/";
        $file_name="qr.png";
        $file_name=$folder.$file_name;
        QRcode::png($text3,$file_name); // used $text3 from the concatenated variables
        echo"<img src='images/qr.png'>";

    //To Display Code Without Storing
    //QRcode::png($text);
    }

However, it is best to also check if any of the inputs are empty.

Sidenote:

In this $text3 = $text1. "" . $text2; you can add anything inside the "" as a separator.

I.e.: using an underscore.

$text3 = $text1. "_" . $text2;

It could also be a space

$text3 = $text1. " " . $text2;
  • The choice is yours.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download