我想问一下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);
}
}
GetCriteria.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;
}
答案 0 :(得分:1)
首先你有这个:
xmlhttp.send("q=" + str);
^---you send a parameter named 'q'
然后你会找到一堆不存在的字段:
$number = $_POST['rowNumber'];
$weightage = $_POST['weightage'.$i];
$points = $_POST['points'.$i];
但您提交的所有内容均为$_POST['q']
。