使用带有Javascript的SQL查询,遇到未定义的函数错误

时间:2022-11-13 01:22:07

I am simply trying to have this one button implement a function that simply shows the users scores for the game overall. This data is updated in an Access DB each time the user plays the game. I don't know if this is an issue with my SQL queries or with my JavaScript coding. I simply need a popup window to display this information when the user clicks this button. Code is as follows:(Just a portion of the code that's supposed to display the popup window, nothing more.)

我只是想让这个按钮实现一个功能,只显示整个游戏的用户分数。每次用户玩游戏时,都会在Access DB中更新此数据。我不知道这是我的SQL查询或我的JavaScript编码的问题。当用户单击此按钮时,我只需要一个弹出窗口来显示此信息。代码如下:(只是应该显示弹出窗口的代码的一部分,仅此而已。)

<button onclick="showscores()" style=" top: 155px; left: 160px; position: absolute;"> Show scores

var user = "FOO";

var myDB = new ACCESSdb("C:\\Users\\FOO\\Users.mdb", {showErrors:true});

function showscores(){
    // select and retrieve the user info data , containing the score data 
    window.alert(myDB.query("SELECT * FROM userInfo WHERE UserName = 'username'));
}

2 个解决方案

#1


1  

You have a syntax error in your query - a missing closing double quote. It should be:

您的查询中存在语法错误 - 缺少结束双引号。它应该是:

window.alert(myDB.query("SELECT * FROM userInfo WHERE UserName = 'username'"));

#2


0  

myDB should be declared within the function unless declared globally, its not clear in your example if that is the case.

myDB应该在函数内声明,除非全局声明,如果是这种情况,它在你的例子中并不清楚。

function showscores(){
    var myDB = new ACCESSdb("C:\\Users\\FOO\\Users.mdb", {showErrors:true});
    // select and retrieve the user info data , containing the score data 
    window.alert(myDB.query("SELECT * FROM userInfo WHERE UserName = 'username'"));
}

#1


1  

You have a syntax error in your query - a missing closing double quote. It should be:

您的查询中存在语法错误 - 缺少结束双引号。它应该是:

window.alert(myDB.query("SELECT * FROM userInfo WHERE UserName = 'username'"));

#2


0  

myDB should be declared within the function unless declared globally, its not clear in your example if that is the case.

myDB应该在函数内声明,除非全局声明,如果是这种情况,它在你的例子中并不清楚。

function showscores(){
    var myDB = new ACCESSdb("C:\\Users\\FOO\\Users.mdb", {showErrors:true});
    // select and retrieve the user info data , containing the score data 
    window.alert(myDB.query("SELECT * FROM userInfo WHERE UserName = 'username'"));
}