0

I have a problem with adding records to the database. To be more specific the static values are correctly added to the table but by looking at the values from text fields they are EMPTY. 0 in the table. I have checked the SQL query and found that I have a bug somewhere because the values obtained from text fields are empty.

Below I am going to show all the functions related to this case, and hopefully you will spot the error which I am trying to resolve.

Function containing SQL query.

function updateGuestSet($no_of_keys, $no_of_fobs) {
    $today = date('Y-m-d H:i:s');
    $keys = array();

    try {
        $transaction = new Transaction();
        $query = 'INSERT INTO `keysets` (`noKeys`, `noFobs`, `masterSet`, `createdate`, `createby`, `keys_idkey`)VALUES("' .$no_of_keys. '","' .$no_of_fobs . '","0","' . $today . '","Jarek","2")';
        echo($query);
        die;
        $keys = QueryExecutor::execute(new SqlQuery($query));
        $transaction -> commit();
    } catch(Exception $e) {
        echo $e;
    }
    return $keys;
}

This is the function used to show/add/remove the field-set

function show_add_guestFields(){
    $('#guestSet').append('<div class="fields"><label for="keys">No. of keys</label><input type="number" name="keys" class="keys" id="keys" onkeypress="return isNumberKey(event);" style="margin: 0px 0px 0px 65px;"/><br/><br/><label for="fobs">No. of fobs</label><input type="number" name="fobs" class="fobs" id="fobs" onkeypress="return isNumberKey(event);" style="margin: 0px 0px 0px 68px;"/><br/><br/><button onClick="valid();">Submit</button><button class="remove" style="margin:0px 0px 10px 0px;">Cancel</button></div>');

    $('#guestSet').on('click', '.remove', function(){
    $(this).parent().remove();
    return false;

});
}

Function related with PHP code

function updateGuestSet(){
    var no_of_keys = $('#keys').val();
    var no_of_fobs = $('#fobs').val();


    $.ajax({
                type: 'POST',
                url: 'propertyId.php',
                data:{
                        update:'keySet',
                        no_of_keys:no_of_keys,
                        no_of_fobs:no_of_fobs
                    },
                async: true,
                dataType:'json',
                success: function(){

                }
        });
}

Finally, this is the PHP code;

if($_POST['update'] == 'keySet'){
    $no_of_keys = $_POST['keys'];
    $no_of_fobs = $_POST['fobs'];
    //echo("test");

    $insert_keySet = updateGuestSet($no_of_keys, $no_of_fobs);


}

This is what I get when I echo the sql query

INSERT INTO keysets (noKeys, noFobs, masterSet, createdate, createby, keys_idkey)VALUES("","","0","2014-11-18 17:37:37","Jarek","2")

THANKS for ALL help!!

2
  • what you say is the output of echo($query) does not match what you pasted Commented Nov 18, 2014 at 22:16
  • What is QueryExecutor::execute? Where does this come from? Why are you not properly escaping your values? Commented Nov 18, 2014 at 22:27

1 Answer 1

1

Desired POST keys:

  • keys
  • fobs

Actual POST keys:

  • no_of_keys
  • no_of_fobs

Just make them the same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.