Why is database looping to add user after user with undefined name and image?
<p>So, I am using Phonegap to take a picture with the camera, insert a name and save that into db. All is fine until it comes to my result set. I am getting an alert, as requested, stating: "ID=1 Name: undefined imagePath: undefined". When I click ok I get the same alert but with two users this time etc. etc. The first problem arises with my insertRecord function. Why is my if statement not preventing this looping of the code or asking the user to enter name and photo? Secondly, why is the name and imagePath undefined, even when I enter both and press the save button. I have stuck the code in jsfiddle here <a href="http://jsfiddle.net/Inkers/rDfRk/" rel="nofollow">http://jsfiddle.net/Inkers/rDfRk/</a> P.S.: I am self-learning so please don't be too harsh!</p>

<pre><code>        function insertRecord(dbtx){
    db = window.openDatabase("database", "1.0", "Profiles", 5000);
    userName=document.getElementById('userName').value;
    imagePath=document.getElementById('placeImage').src;
    if(userName==null){
    alert('Please enter a name');
    }
    if(imagePath==null){
    alert('Please take a picture');
    }
    if(userName !== null &amp;&amp; imagePath !== null){

var insertRec="INSERT INTO USERS (username, imagePath) values (?, ?)";
    db.transaction(function(dbtx){dbtx.executeSql(insertRec, [userName, imagePath], queryDB, insFail);
    });
}   
}
// Query the database
//
function insFail(){
    alert('The insert is still failing');
}

function queryDB(dbtx) {
    var getUsers = "SELECT * FROM USERS ORDER BY id ASC";
    db.transaction(function (dbtx){dbtx.executeSql(getUsers, [], querySuccess, queryFailure);}, errorCB, successCB);
}

// Query the success callback
//
function querySuccess(dbtx, results) {
   var len = results.rows.length;
    for (var i=0; i&lt;len; i++){
    alert(" ID = " + results.rows.item(i).id + " Name =  " + results.rows.item(i).name + " Image Path = " + results.rows.item(i).image);
    }

     console.log("You are in the querysuccess function");
}
</code></pre>
