gpt4 book ai didi

javascript - 查询/PHP : Result of jQuery function into PHP variable

转载 作者:行者123 更新时间:2023-11-29 00:22:28 25 4
gpt4 key购买 nike

我有一个关于 Java 和 PHP 的小问题。我没有在这个论坛中找到我要找的东西,所以我觉得最好问一下。

我有一个 Javascript 函数(见下文)但不是我自己制作的!当客户更改多选按钮时,它会自动计算并计算总价。

function fncCheck() {
var subtotaal = 0;
var combikorting = 0;
var totaal = 0;
var toeslagcontant = 0;
var totaaltebetalen = 0;

if (document.getElementById("ek").checked == true && document.getElementById("epc").checked == false) {
subtotaal = subtotaal + 115;
toeslagcontant = 5;
document.getElementById("elektrischekeuring").style.display = "block";
} else {
document.getElementById("elektrischekeuring").style.display = "none";
}

if (document.getElementById("ek").checked == true && document.getElementById("epc").checked == true) {
subtotaal = subtotaal + 125;
toeslagcontant = 5;
document.getElementById("elektrischekeuring").style.display = "block";
} else {
document.getElementById("elektrischekeuring").style.display = "none";
}

if (document.getElementById("epc").checked == true) {
if (document.getElementById("studio").checked == true) {
subtotaal = subtotaal + 115;
} else if (document.getElementById("appartement").checked == true) {
subtotaal = subtotaal + 140;
} else if (document.getElementById("rijwoning").checked == true) {
subtotaal = subtotaal + 165;
} else if (document.getElementById("halfopenwoning").checked == true) {
subtotaal = subtotaal + 165;
} else if (document.getElementById("vrijstaandewoning").checked == true) {
subtotaal = subtotaal + 170;
}
toeslagcontant = 5;
}

if (document.getElementById("gk").checked == true) {
subtotaal = subtotaal + 130;
toeslagcontant = 5;
}

if (document.getElementById("ek").checked == true && document.getElementById("epc").checked == true) {
if (document.getElementById("studio").checked == true) {
combikorting = 0;
} else if (document.getElementById("appartement").checked == true) {
combikorting = 10;
} else if (document.getElementById("rijwoning").checked == true) {
combikorting = 15;
} else if (document.getElementById("halfopenwoning").checked == true) {
combikorting = 15;
} else if (document.getElementById("vrijstaandewoning").checked == true) {
combikorting = 10;
}
}

totaal = subtotaal - combikorting


document.getElementById("totaal").innerHTML = totaal + " EUR";

if (document.getElementById("terplaatse").checked == true) {
totaaltebetalen = totaal + toeslagcontant;
} else {
totaaltebetalen = totaal;
}

document.getElementById("totaaltebetalen").innerHTML = totaaltebetalen + " EUR";
}

HTML:

<h2>Total à payer:</h2><br />
<table cellpadding="0" cellspacing="0" border="0" style="width:270px;">
<tr style="height:25px">
<td>&nbsp;</td>
<td><strong class="pricetext"><div id="totaaltebetalen">0 EUR</div></strong></td>
</tr>
</table>

我想将“totaaltebetalen”(价格)插入我的数据库。我如何将它存储到一个变量中,以便我可以同时对所有其他变量执行“INSERT INTO”。

最佳答案

你应该在服务器端计算总数,使用你的数据库的价格,而不是用户提交的任何东西,否则恶意客户端可以提交他们自己的总数,而你的服务器会接受它。 (例如价格=-10000.00),除非您实际上是在向用户询问价格,例如您想以多少价格出售您的元素......

提交的表单将有一个与之关联的“操作”(将处理表单上提交的数据的 url)

表单的字段将通过 $_POST$_GET$_REQUEST 变量提供给 php。然后,您可以使用表单的输入字段值在服务器端计算价格。

例如$_POST['apartmentID']

编辑/附加

因此,如果您的输入名称是 ek、gpc 和 gk,您可以在 PHP 中执行以下操作:

$value = 0;
$discount = 0;
if (!empty($_REQUEST['ek'])){ //this will only be set if the item was ticked/checked
$value = 100;
$ek_chk = true;
}
if (!empty($_REQUEST['epc'])){
$value += 150; // not to sure here if you want to add to or replace value
if ($ek_chk) $discount = 0.2;
}
if (!empty ($_REQUEST['gpc'])){
$value += 200;
}
$total = $value * (1-$discount);
....
//save total to database;
....

关于javascript - 查询/PHP : Result of jQuery function into PHP variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612343/

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