First time posting.
I am working on an application were the user scans a qr code and the information relating to that qr code is stored in a database. So far this is what I have ...
This is the scanner functions
- $(document).ready(function () {
- $("#insert").click(function () {
- var serial_no = window.localStorage.getItem("serial");
- var user_name = window.localStorage.getItem("user_name");
- var company_id = window.localStorage.getItem("id");
- var distributor = window.localStorage.getItem("distributor");
- var date = date_time('date_time');
- var n = company_id.toString();
- //document.getElementById("date_time").innerHTML = company_id;
- var dataString = "company_id=" + n + "&distributor=" + distributor + "&title=" + serial_no + "&location=" + user_name + "&frequency=" + date + "&insert=";
- //var dataString = {company_id: n, distributor: distributor, title: serial_no, location: user_name, frequency: date, insert};
- $.ajax({
- type: "POST",
- url: "http://system/mobileDB/scanned.php",
- data: dataString,
- crossDomain: true,
- cache: false,
- beforeSend: function () {
- $("#insert").val('Connecting...');
- },
- success: function (data) {
- if (data === "success") {
- } else if (data === "error") {
- alert("error");
- }
- }
- });
- });
- });
I think my problem stems from the fact that I have .click. When the user loads this page it goes straight into a scanner. Then once they scan the qr code the information appears on screen. So the this insert button never appears on screen.
This is the scanned.php that is receiving the data.
- <?php
- include "db.php";
- $user_name=$_POST['location'];
- $date=$_POST['frequency'];
- $serial_no=$_POST['title'];
- $customer_id=$_POST['company_id'];
- $distributor=$_POST['distributor'];
- if(!isset($customer_id))
- {
- $customer_id = 1;
- }
-
- $q=mysqli_query($con,"INSERT INTO `recently_scanned` (user_id, user_details, distributor, serial_no, scanDate) VALUES ('$customer_id', '$user_name', ' $distributor', '$serial_no', '$date')");
- if($q)
- echo "success";
- else
- echo "error";
- ?>
This page throws an error saying all indexs are undefined because it is being passed nothing.
My question is how do I get my insert function to run as soon as a qr code is scanned ?
Thanks in advance for the help.