Sending Data

Sending Data

Hi guys,

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
    1.  $(document).ready(function () {
    2.                 $("#insert").click(function () {
    3.                     var serial_no = window.localStorage.getItem("serial");
    4.                     var user_name = window.localStorage.getItem("user_name");
    5.                     var company_id = window.localStorage.getItem("id");
    6.                     var distributor = window.localStorage.getItem("distributor");
    7.                     var date = date_time('date_time');
    8.                     var n = company_id.toString();
    9.                     //document.getElementById("date_time").innerHTML = company_id;

    10.                     var dataString = "company_id=" + n + "&distributor=" + distributor + "&title=" + serial_no + "&location=" + user_name + "&frequency=" + date + "&insert=";
    11.                     //var dataString = {company_id: n, distributor: distributor, title: serial_no, location: user_name, frequency: date, insert};
    12.                     $.ajax({
    13.                         type: "POST",
    14.                         url: "http://system/mobileDB/scanned.php",
    15.                         data: dataString,
    16.                         crossDomain: true,
    17.                         cache: false,
    18.                         beforeSend: function () {
    19.                             $("#insert").val('Connecting...');
    20.                         },
    21.                         success: function (data) {
    22.                             if (data === "success") {
    23.                             } else if (data === "error") {
    24.                                 alert("error");
    25.                             }
    26.                         }
    27.                     });
    28.                 });
    29.             }); 
    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.

    1. <input type="button" id="insert" class="button button-block" value="Insert" style="display: none;"/>
    But since this button is never clicked nothing ever happens.

    This is the scanned.php that is receiving the data.
    1. <?php
    2.  include "db.php";


    3.  $user_name=$_POST['location'];
    4.  $date=$_POST['frequency'];
    5.  $serial_no=$_POST['title'];
    6.  $customer_id=$_POST['company_id'];
    7.  $distributor=$_POST['distributor'];

    8. if(!isset($customer_id))
    9. {
    10. $customer_id = 1;
    11. }
    12.  
    13.  $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')"); 
    14.  if($q)
    15.   echo "success";
    16.  else
    17.   echo "error";

    18.  ?>
    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.