jeudi 10 mars 2016

PHP sqlite not updating with AJAX

I'm running Firebug to track what happens when I use Ajax to try to update a lot I have, and everything in firebug is pointing me in the direction that nothing is going wrong - but the log is never updated.

My form + ajax:

<form id="submitTRG" method="GET" action="ajax/submit.php">
                                    <div class="form-group">
                                        <label for="trgID">TRG ID</label>
                                        <input type="text" class="form-control" id="trgID" name="trgID" placeholder="TRG ID #" autofocus><br>
                                        <input type="submit" class="btn btn-success" id="trgIDSubmit" name="Submit">
                                    </div>
                                </form>
                                <script>
                                $(document).ready(function() {
                                   $('#submitTRG').submit( function( event ) {
                                       $.ajax({ // create an AJAX call...
                                           data: $('#submitTRG').serialize(), // serialize the form
                                           type: $('#submitTRG').attr('method'), // GET or POST from the form
                                           url: $('#submitTRG').attr('action'), // the file to call from the form
                                           success: function(response) { // on success..
                                               $('#trgID').val('');
                                           }
                                       });
                                       event.preventDefault();
                                    });
                                });
                                </script>

My PHP catch ajax script:

session_start();

    $date = $_SESSION['date'];
    $tech = $_SESSION['tech'];
    $type = $_SESSION['type'];
    $func = $_SESSION['func'];
    $trg = $_GET['trgID'];

    class MyDB2 extends SQLite3
            {
                function __construct() {
                    $this->open('../DB/test.db');
                } 
            }

    $test = new MyDB2();
    if(!$test){
        echo $test->lastErrorMsg();
    } else {
        echo "Connected<br>";
    }

    echo "inserting: " . $date . " - " . $tech . " - " . $type . " - " . $func . " - " . $trg;
    $sql ="INSERT INTO req (uniqueID,upd,time,tech,type,func,trg) VALUES (NULL, '0', '$date', '$tech', '$type', '$func', '$trg');";

    if(strcmp($trg,'') != 0) {
        $inp = $test->query($sql);
        if(!$inp){
            echo $test->lastErrorMsg();
        } else {
            echo "<br>completed";
        }
    } else {
        //do nothing
    }

    $test->close();

I'm sure this is something small that I am missing but I just cannot figure out what's going on.

In firebug, this is the response I am getting every time the form is ran. Connected<br>inserting: 03/10/2016 - *tech - *type - $func - *id<br>completed

I have checked, double checked, and triple checked my database to make sure the right information is being inputted into the right field - that's not the problem.

Aucun commentaire:

Enregistrer un commentaire