如何在js中读取db值


How to read db value in js

如何从js脚本中读取db值?1)我有以下代码行,我想修改以读取数据库表中的值

var admin_status=document.form1.admin_status.value;
if(admin_status == 0 && document.form1.ecurr_amount.value>20) 
{
document.getElementById('msg').innerHTML='Please Verify Your Account to process.';  
return false;
}

这个:

<input type="hidden" name="admin_status" id="admin_status" 
value="<?php echo $obj_db->
fetch_field("select status from tbl_verification_docs where 
userid = '".$_SESSION['user_user']['id']."'")?>" />

我使用这些行来验证表单-->以修复最小值

a) 我希望验证来自数据中托管的值(因为我想从管理面板而不是脚本控制该值)

现在我有

"if(admin_status == 0 && document.form1.ecurr_amount.value>20)" 

如果我想改变这个值,我需要改变脚本-->我现在想要的是从数据库中的条目中读取"20"

if($data_logged_user['admin_status']=='0' && $data_nbtrans_user['COUNT(*)'] > 5 ) 
{
if($data_nbtrans_user['COUNT(*)'] > 5) 
{
echo "Sorry you have reach your max number of transaction for the day, 
come back tomorrow or <a href='http://e-dollar.ng/new-portal/members/accountverification'>
Click here</a> to Verify your Account Now.";
}
}
else 
{
my form goes here..
}

b) 这里我控制事务的数量(它被设置为>5)

我想从数据值中读取"5",而不是

我有我的数据库表"tbl_settings"

这就是我的tbl_settings(从我的数据库)的样子

Setting          Value   type
SITE_STATUS     |  1   | enum
MAX_AMOUNT      |  20  | integer
MAX_TRANSACTION |  5   | integer

这是AJAX调用的基本内容,但我建议对其进行更彻底的研究。

因此,在myAjax函数中,您将ajaxURL设置为将进行数据库调用的PHP文件。值被传递到URL中的PHP文件,注意到value1被传递到myAjax函数吗?你可以通过这种方式添加你需要的所有值。

PHP文件应该通过echo输出基于数据库调用的文本结果。

可以通过Javascript中的http.responseText访问此echo。

function myAjax(value1) {
var http = getHTTPObject();
var ajaxUrl ="theUrl.php?";
http.open("GET", ajaxUrl  + "value1=" + value1, false);
http.send(null);  
alert(http.responseText);

}

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try 
        {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
        xmlhttp = false;
        }
    }
    return xmlhttp;
}