0

好的,假设我有一个工作数据库连接和表来插入名称和用相机拍摄的图像。当我尝试插入记录时,我已经使用以下语句对其进行了测试。

    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

所以,我认为我说他们有某种不为空的价值是对的。然而,当我从用户中选择 * 时,我得到 ID:1 名称:未定义的图像路径:未定义。我不认为这是范围的问题,因为我已经完成了它,应该没问题。它可能与我的 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');
    }
}

我看不出用户名和图像路径在进入数据库时​​仍未定义的任何原因。我没有正确地给他们价值吗?我知道我正在调用 getPhoto(); 对于图片,但这又会调用 onPhotoURISuccess(); (这可能是个问题吗?)我是否正确使用了 onchange。我应该对图像输入进行类似的测试吗?任何帮助或方向表示赞赏。

4

1 回答 1

1

我没有name在您的输入中看到 attr .. 如果您发布它..

 <input id="placeImage" name="imagePath" type="image" onclick="getPhoto();" style="width:60px;height:60px" /> 
<p></p>

<input id="userName" type="text" name="userName" placeholder="FirstName" onchange="getName();"> name<br>

<input id="saveProfile" type="button" value="Save" onClick="insertRecord(dbtx);"> <br>
于 2013-01-15T12:45:00.770 回答