Jacque
Jacque

Reputation: 21

How to send the value of JavaScript to PHP and then My SQL database?

I want to save the image or the value of the QR code/decodedText variable into My SQL database using PHP. Here is the code:

 <div class="container" style="padding-left: 25%;"> 
  <div class="row"> 
   <div id="qr-reader" style="width: 600px"></div> 
  </div> 
 </div>

And the JavaScript

    <script> 
     function onScanSuccess(decodedText, decodedResult) { 
     console.log(`Code scanned = ${decodedText}`, decodedResult); 
     } 
   var html5QrcodeScanner = new Html5QrcodeScanner( "qr-reader", { 
     fps: 10, qrbox: 250 }); 
     html5QrcodeScanner.render(onScanSuccess); 
    </script>
    <script src="https://unpkg.com/[email protected]/dist/html5-qrcode.min.js"></script>

Upvotes: 1

Views: 116

Answers (1)

Lukas249
Lukas249

Reputation: 2471

Use fetch and formData

fetch("file.php", method:"POST", data: formData)

then in php you connect with mysql

$conn = new mysqli("localhost", "root", "", "db");
$conn->query("ISERT INTO .....")

Upvotes: 1

Related Questions