gpt4 book ai didi

php - $_POST 冲突?

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

我想问php中$_POST有冲突吗?我有一个 $_POST 使用 ajax 从上一个 php 页面 (ASKAssessmentMarks.php) 获取值,然后我想从输入文本 (GetCriteria.php) 获取另一个值

ASKAssessmentMarks.php

    function showCriteria(str){
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}

//xmlhttp.open("GET","GetCriteria.php?q="+str,true);
//xmlhttp.send();

xmlhttp.open("POST", "GetCriteria.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("q=" + str);
}
}

获取条件.php

$id =0;
$no = 1;

$rowNumber = mysql_num_rows($result_2);

echo '<form action="" method="post">';
echo "<input type ='hidden' name='rowNumber' value='$rowNumber'>";

while($row = mysql_fetch_array($result_2)){

echo "<input type ='hidden' name='weightage$id' value=".$row['weightage'].">";
echo "<input type ='hidden' name='points$id' id='points$id'>";

echo '<tr><td align = "center">'.$no.'</td>';
echo '<td align = "center">'.$row['criteria_name'].'</td>';
echo '<td align = "center">'.$row['weightage'].'</td>';
echo
'<td><input type="range" name="criteria_'.$id.'" min="0" max="5" value="0" step="1" id = "slider" style="width:700px" onchange="showValue('.$id.',this.value)" />
<label style="margin-left: 65px"></label>
<label style="margin-left: 55px">Very Poor</label>
<label style="margin-left: 75px">Poor</label>
<label style="margin-left: 80px">Moderate</label>
<label style="margin-left: 90px">Good</label>
<label style="margin-left: 70px">Excellent</label></td>
<td align = "center"><span id="range'.$id.'">0</span></td>';

$id++;
$no++;

}
echo "</tr></table>";
echo '<br/><button>Compute Score</button><br/>';
echo "</form>";


if(isset($_POST['rowNumber'])){

echo "<script>alert('Total mark is calculated!')</script>";

//Get the total row number from database
$number = $_POST['rowNumber'];

$totalPercentage = 0;
$total_02 = 0;

//Calculate the result
for($i = 0; $i < $number; $i++){

$weightage = $_POST['weightage'.$i];
$points = $_POST['points'.$i];

//Calculate total weightage
$total_01 = $weightage * 5;
$total_02 += $total_01;

//Calculate total points gained
$subTotal = $weightage * $points;
$totalPercentage += $subTotal;

}

最佳答案

首先你有这个:

        xmlhttp.send("q=" + str);
^---you send a parameter named 'q'

然后你寻找一堆不存在的字段:

$number = $_POST['rowNumber'];
$weightage = $_POST['weightage'.$i];
$points = $_POST['points'.$i];

但您提交的只是$_POST['q']

关于php - $_POST 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30440968/

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