What is wrong with my code?

Hello, I have a webpage were the user can generate a qr code based on their input, and download it. This qr code then leads to a dynamic page that shows the users inputs. I accomplish this with a QRcode library for the qr code generation part, and an iframe for the download (I send the qr code svg as a message to the iframe). My problem is that when the users clicks on the submit button, the users inputs are not being sent to the database and thus, no dynamic page is created.

Here is my code:

import { generateQRcode } from ‘backend/qrCode.jsw’ ;
import wixData from ‘wix-data’ ;

$w.onReady( function () {
$w( “#vectorImage1” ).hide
$w( ‘#html1’ ).hide
});

export function button2_click(event) {
let codeToEncode = “https://peperendon02.wixsite.com/mysite/menu/” + $w( “#input2” ).value; //use your own code
generateQRcode(codeToEncode).then(qr => {
$w( “#vectorImage1” ).src = qr;
$w( “#vectorImage1” ).show();
$w( ‘#html1’ ).show();
let toInsert = {
“title” : $w( ‘#input2’ ).value,
“thing” : $w( ‘#input3’ ).value,
“thing2” : $w( ‘#input4’ ).value,
“qr” : qr,
};
wixData.insert( “Mydatabase” , toInsert)
$w( “#html1” ).postMessage(qr);
})
}

Hi Jose. Just by looking at your code I see 2 things that might need adjustment:
1: $w( ’ #html1 ’ ).show(); is a bit early. There is nothing to show yet, you have not postmessaged it yet
2: wixData.insert( “Mydatabase” , toInsert) returns a Promise, but you don´t wait for it. Ty this:
a) export async function button2_click(event) {
b) await wixData.insert( “Mydatabase” , toInsert)
c) now show the html component content

Good luck