weixin_33735077 2015-05-25 14:50 采纳率: 0%
浏览 12

$ POST有冲突吗?

I want to ask is there any $_POST conflict in php? I have one $_POST to get the value from previous php page (ASKAssessmentMarks.php) using ajax and then I want to get another value from the input text (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;

}
  • 写回答

1条回答 默认 最新

  • weixin_33724659 2015-05-25 14:52
    关注

    First you have this:

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

    and then you look for a bunch of fields that don't exist:

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

    but all you ever submitted is $_POST['q'].

    评论

报告相同问题?

悬赏问题

  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥15 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。
  • ¥15 matlab如何根据图片中的公式绘制e和v的曲线图
  • ¥15 我想用Python(Django)+Vue搭建一个用户登录界面,但是在运行npm run serve时报错了如何解决?