1

I'm making an html question form. Based on the answers, it performs JavaScript algorithms. Then JavaScript takes the numbers it calculated and uses document.getElementById to put the answers in a hidden html form. PHP puts the form into variables, and updates the MYSQL row that was selected. I didn't show the actual calculations because it is over 300 lines of code. The values in the database are blank every time I click submit. Thanks to anyone who can help me out!!!

<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'");
}
?>

3
  • I don't see $idchosen anywhere.. Commented Jun 4, 2016 at 20:21
  • First of all, don't use mysql library. Second, don't use variables as strings in your queries. Use parameters instead. Also, I've a few questions: 1-) Where does this form submit? Are you sure you're posting it to right PHP script? 2-) You're trying to update, are you sure that the data is already at the database? 3-) Can you print your POST values or they're empty too? Commented Jun 4, 2016 at 20:40
  • I figured it out. The problem was that the $question vairables in the SQL part were not capitalized. Thanks for the feedback though!! :) Commented Jun 5, 2016 at 20:22

1 Answer 1

1

Maybe you would use the same case for variables? If you have var $Question4aa, it should be the same in mysql string, not $question4aa

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! I spent almost 5 hours looking for something simple like that. Thank you so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.