gpt4 book ai didi

javascript - 如何在js中读取db值

转载 作者:行者123 更新时间:2023-11-29 23:47:05 25 4
gpt4 key购买 nike

如何从 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 的样子(来 self 的数据库)

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

最佳答案

这是 AJAX 调用的基本框架,但我建议更彻底地研究它。

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

PHP 文件应根据数据库调用通过回显输出文本结果。

此回显可通过 Javascript 中的 http.responseText 访问。

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;
}

关于javascript - 如何在js中读取db值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25857342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com