PHP表单不会基于javascript提交给MYSQL数据库

时间:2016-06-04 20:12:39

标签: javascript php html mysql database

我正在制作一个html问题表单。根据答案,它执行JavaScript算法。然后JavaScript获取它计算的数字并使用document.getElementById将答案放在隐藏的html表单中。 PHP将表单放入变量,并更新所选的MYSQL行。我没有显示实际的计算,因为它超过300行代码。每次单击“提交”时,数据库中的值都是空白的。感谢任何可以帮助我的人!!!

<html>
<form method="post" id="formformid">
//These are where the JavaScript values are entered.
        <input class="hidden" name="processfnumaa" id="processfnum" type="number" value="0">
        <input class="hidden" name="technologyfnumaa" id="technologyfnum" type="number" value="0">
        <input class="hidden" name="staffingfnumaa" id="staffingfnum" type="number" value="0">
        <input class="hidden" name="Question4aa" id="Question4aa" type="text">
        <input class="hidden" name="Question5aa" id="Question5aa" type="text">
        <input class="hidden" name="Question6aa" id="Question6aa" type="text">
        <input class="hidden" name="Question7aa" id="Question7aa" type="text">
        <input class="hidden" name="Question8aa" id="Question8aa" type="text">
        <input class="hidden" name="Question9aa" id="Question9aa" type="text">
        <input class="hidden" name="Question10aa" id="Question10aa" type="text">
        <input class="hidden" name="Question11aa" id="Question11aa" type="text">
        <input class="hidden" name="Question12aa" id="Question12aa" type="text">
        <input class="hidden" name="Question13aa" id="Question13aa" type="text">
        <input class="hidden" name="Question14aa" id="Question14aa" type="text">
        <input class="hidden" name="Question15aa" id="Question15aa" type="text">
        <input class="hidden" name="Question16aa" id="Question16aa" type="text">
        <input class="hidden" name="Question17aa" id="Question17aa" type="text">
        <input class="hidden" name="Question18aa" id="Question18aa" type="text">
        <input class="hidden" name="Question19aa" id="Question19aa" type="text">
        <input class="hidden" name="Question20aa" id="Question20aa" type="text">
        <input class="hidden" name="Question21aa" id="Question21aa" type="text">
        <input class="hidden" name="Question22aa" id="Question22aa" type="text">
        <input class="hidden" name="Question23aa" id="Question23aa" type="text">
        <input class="hidden" name="Question24aa" id="Question24aa" type="text">
        <input class="hidden" name="Question25aa" id="Question25aa" type="text">

        <input type="button" id="savebutton" onclick="submitthatform()" value="Save Changes" style="display: none;" />
    </form>
    

//This function is called when the user is done editing the answers in a different form.
    <script type="text/javascript">
    function submitthatform() {}
            document.getElementById("Question4aa").value = a;
            document.getElementById("Question5aa").value = b;
            document.getElementById("Question6aa").value = c;
            document.getElementById("Question7aa").value = d;
            document.getElementById("Question8aa").value = e;
            document.getElementById("Question9aa").value = f;
            document.getElementById("Question10aa").value = g;
            document.getElementById("Question11aa").value = h;
            document.getElementById("Question12aa").value = i;
            document.getElementById("Question13aa").value = j;
            document.getElementById("Question14aa").value = k;
            document.getElementById("Question15aa").value = l;
            document.getElementById("Question16aa").value = m;
            document.getElementById("Question17aa").value = n;
            document.getElementById("Question18aa").value = o;
            document.getElementById("Question19aa").value = p;
            document.getElementById("Question20aa").value = q;
            document.getElementById("Question21aa").value = r;
            document.getElementById("Question22aa").value = s;
            document.getElementById("Question23aa").value = t;
            document.getElementById("Question24aa").value = u;
            document.getElementById("Question25aa").value = v;
            var awsasdg = document.getElementById("Question4aa").value;
            alert(awsasdg);
            document.getElementById("processfnum").value = processfinalnumber;
            document.getElementById("technologyfnum").value = technologyfinalnumber;
            document.getElementById("staffingfnum").value = staffingfinalnumber;
            document.getElementById("formformid").submit();
        }
    </script>
    
</html>







<?php

//Here, I'm trying to update a row in my database.  This is just the part of the file that ends up blank in the database.  

$Question4aa = mysql_real_escape_string($_POST['Question4aa']);
 $Question5aa = mysql_real_escape_string($_POST['Question5aa']);
 $Question6aa = mysql_real_escape_string($_POST['Question6aa']);
 $Question7aa = mysql_real_escape_string($_POST['Question7aa']);
 $Question8aa = mysql_real_escape_string($_POST['Question8aa']);
 $Question9aa = mysql_real_escape_string($_POST['Question9aa']);
 $Question10aa = mysql_real_escape_string($_POST['Question10aa']);
 $Question11aa = mysql_real_escape_string($_POST['Question11aa']);
 $Question12aa = mysql_real_escape_string($_POST['Question12aa']);
 $Question13aa = mysql_real_escape_string($_POST['Question13aa']);
 $Question14aa = mysql_real_escape_string($_POST['Question14aa']);
 $Question15aa = mysql_real_escape_string($_POST['Question15aa']);
 $Question16aa = mysql_real_escape_string($_POST['Question16aa']);
 $Question17aa = mysql_real_escape_string($_POST['Question17aa']);
 $Question18aa = mysql_real_escape_string($_POST['Question18aa']);
 $Question19aa = mysql_real_escape_string($_POST['Question19aa']);
 $Question20aa = mysql_real_escape_string($_POST['Question20aa']);
 $Question21aa = mysql_real_escape_string($_POST['Question21aa']);
 $Question22aa = mysql_real_escape_string($_POST['Question22aa']);
 $Question23aa = mysql_real_escape_string($_POST['Question23aa']);
 $Question24aa = mysql_real_escape_string($_POST['Question24aa']);
 $Question25aa = mysql_real_escape_string($_POST['Question25aa']);
 $processfnumaa = mysql_real_escape_string($_POST['processfnumaa']);
 $technologyfnumaa = mysql_real_escape_string($_POST['technologyfnumaa']);
 $staffingfnumaa = mysql_real_escape_string($_POST['staffingfnumaa']);

if($_SERVER['REQUEST_METHOD'] === 'POST'){

    
     mysql_query("UPDATE HuronForm1 SET Question4aa='$question4aa',Question5aa='$question5aa',Question6aa='$question6aa',Question7aa='$question7aa',Question8aa='$question8aa',Question9aa='$question9aa',Question10aa='$question10aa',Question11aa='$question11aa',Question12aa='$question12aa',Question13aa='$question13aa',Question14aa='$question14aa',Question15aa='$question15aa',Question16aa='$question16aa',Question17aa='$question17aa',Question18aa='$question18aa',Question19aa='$question19aa',Question20aa='$question20aa',Question21aa='$question21aa',Question22aa='$question22aa',Question23aa='$question23aa',Question24aa='$question24aa', processfnum='$processfnumaa', technologyfnum='$technologyfnumaa',staffingfnum='$staffingfnumaa',Question25aa='$question25aa' WHERE Id='$idchosen'");
}
?>

1 个答案:

答案 0 :(得分:1)

也许你会对变量使用相同的情况? 如果你有var $ Q uestion4aa,它应该在mysql字符串中相同,而不是$ q uestion4aa