OK、カメラで撮影した名前と画像を挿入するためのデータベース接続とテーブルが機能していると仮定します。レコードを挿入しようとすると、次のステートメントでテストしました。
function insertRecord(){
userName;
imagePath;
if(userName=='' || imagePath==''){insert the stuff}// this won't run the insert statement
if(userName!='' && imagePath!=''){insert the stuff} //this is giving me results but undefined
ですから、私が正しいと思うのは、それらにはnullではないある種の価値があるということです。それでも、* FROM USERSを選択すると、ID:1 name:undefined imagepath:undefinedを取得します。私はそれを経験したので、これはスコープの問題ではないと思います、そしてそれは大丈夫であるはずです。それは私のhtml入力と関係があるのでしょうか。現時点では、両方のhtml入力は次のようになっています。
<input id="placeImage" type="image" onclick="getPhoto();" style="width:60px;height:60px" />
<p></p>
<input id="userName" type="text" placeholder="FirstName" onchange="getName();"> name<br>
<input id="saveProfile" type="button" value="Save" onClick="insertRecord(dbtx);"> <br>
ご覧のとおり、画像入力は単にカメラを呼び出して画像を取得し、結果のパスを、グローバル変数imagePath(insertRecordで使用される)に割り当てている成功関数に渡します。
function getPhoto() {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: pictureSource
});
}
function onPhotoURISuccess(imageURI){
console.log('calling success function');
placeImage = document.getElementById('placeImage');
if(placeImage==''){
alert('Please take a photo');
}else{
placeImage.src = imageURI;
alert(placeImage.src);
placeImage.style.display = 'block';
imagePath=placeImage.src;
}
console.log(imageURI);
}
function onFail(message) {
alert('Failed because: ' + message);
}
同様に、名前を入力して、onchange = "getName();"を使用しています。このコードを呼び出すには
function getName(){
userName= document.getElementById('userName').value;
if(userName==''){
alert('Please enter a name');
}
}
ユーザー名とimagePathがデータベースに入るときにまだ定義されていない理由はわかりません。私はそれらに正しく値を与えていませんか?getPhoto();を呼び出していることはわかっています。写真の場合、しかしそれは順番にonPhotoURISuccess();を呼び出します。(これは問題になる可能性がありますか?)onchangeを正しく使用していますか?画像入力で同様のテストを行う必要がありますか?どんな助けや指示もありがたいです。