www.webdeveloper.com
Results 1 to 11 of 11

Thread: insert data from PHP and Javascript into database problem

  1. #1
    Join Date
    Aug 2014
    Posts
    6

    insert data from PHP and Javascript into database problem

    hi, everyone.
    I am really newbie here about codes. I need someone here to help me how can I insert data generated by javascript into database?
    I dying to gain help. below I attached my complete php and javascript file for your reference. I need to know any ideas about how can i save the result into database, Thank you and have nice day.
    question.txt
    cuba.txt

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    853
    Show us the php handling the input data - how you get it into your php vars and then show us what you do with those vars as you write your db query. Please post the code properly in the forum, not somewhere else.

  3. #3
    Join Date
    Aug 2014
    Posts
    6

    my php file used to display the question

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Learning Style Questionnaire</title>

    <script language="JavaScript1.2" src="cuba.js" type="text/javascript"></script>
    </head>

    <body>

    <div id="container">

    <div id="Questions">

    <div id="Instructions">

    <h1>Learning Style Questionnaire</h1>

    <B> Instructions </B>
     <p>Read each statement carefully. Answer honestly as there are no correct or incorrect answers.
     It is best if you do not think about each question too long, as this could lead you to the wrong conclusion..</p>
    <p></p>
    </div> <!-- Instructions -->
    <?php include 'db.php';
    /*$question = mysql_query("SELECT * FROM tbl_ferquestion") 
            or die(mysql_error());  
    $row = mysql_fetch_array($question);
    $answer1 = mysql_query("SELECT ans1 FROM tbl_ferquestion") 
            or die(mysql_error());  
    $ans1 = mysql_fetch_array($answer1);*/
    ?>
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" align="center">
    <caption><h2><b>Learning Styles Questionnaire</b></h2></caption>
    <caption><h3><b>SECTION 1 (Doing & Watching)</b></h3></caption>
    <tr>
    <form name="Question1" id="Question1">
    <tr><td class="question">1. 
    <input type="radio" value="radio0" name="radio" id="rad1-1"/>
    <label for="radio1-1" class="radiobutton">I often produce off-the-cuff ideas that at first might seem silly or half-baked.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="rad1-2"/>
    <label for="radio1-2" class="radiobutton">I am thorough and methodical.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question2" id="Question2">
    <tr><td class="question">2. 
    <input type="radio" value="radio0" name="radio" id="rad2-1"/>
    <label for="radio2-1" class="radiobutton"> I am normally the one who initiates conversations.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="rad2-2"/>
    <label for="radio2-2" class="radiobutton"> I enjoy watching people.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question3" id="Question3">
    <tr><td class="question">3.
    <input type="radio" value="radio0" name="radio" id="radio3-1"/>
    <label for="radio3-1" class="radiobutton"> I am flexible and open minded.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio3-2"/>
    <label for="radio3-2" class="radiobutton"> I am careful and cautious.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question4" id="Question4">
    <tr><td class="question">4.
    <input type="radio" value="radio0" name="radio" id="radio4-1"/>
    <label for="radio4-1" class="radiobutton">  I like to try new and different things without too much preparation.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio4-2"/>
    <label for="radio4-2" class="radiobutton">  I investigate a new topic or process in depth before trying it.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question5" id="Question5">
    <tr><td class="question">5.
    <input type="radio" value="radio0" name="radio" id="radio5-1"/>
    <label for="radio5-1" class="radiobutton"> I am happy to have a go at new things.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio5-2"/>
    <label for="radio5-2" class="radiobutton">  I draw up lists up possible courses of actions when starting a new project. </label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question6" id="Question6">
    <tr><td class="question">6.
    <input type="radio" value="radio0" name="radio" id="radio6-1"/>
    <label for="radio6-1" class="radiobutton">   I like to get involved and to participate.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio6-2"/>
    <label for="radio6-2" class="radiobutton">  I like to read and observe.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question7" id="Question7">
    <tr><td class="question">7.
    <input type="radio" value="radio0" name="radio" id="radio7-1"/>
    <label for="radio7-1" class="radiobutton">  I am loud and outgoing.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio7-2"/>
    <label for="radio7-2" class="radiobutton">   I am quiet and somewhat shy.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question8" id="Question8">
    <tr><td class="question">8.
    <input type="radio" value="radio0" name="radio" id="radio8-1"/>
    <label for="radio8-1" class="radiobutton"> I make quick and bold decisions.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio8-2"/>
    <label for="radio8-2" class="radiobutton">  I make cautious and logical decisions.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    <tr>
    <form name="Question9" id="Question9">
    <tr><td class="question">9.
    <input type="radio" value="radio0" name="radio" id="radio9-1"/>
    <label for="radio9-1" class="radiobutton">   I speak fast, while thinking.</label></td></tr>
    <tr><td>&nbsp&nbsp&nbsp
    <input type="radio" value="radio1" name="radio" id="radio9-2"/>
    <label for="radio9-2" class="radiobutton">  I speak slowly, after thinking.</label></td></tr>
    </form>
    </tr>
    <tr><td>&nbsp&nbsp&nbsp </td></tr>
    </table>

    <form id="form_end" action="insertResult.php">
    <p>After answering each question, click on the button below.<p>
    <p></p>
    <input name="Determine Style" type="button" value="Determine Style" onClick="determineStyle()">
    </form>

    </div> <!-- End of Questions -->

    <hr>

    <div id="results" aria-live="polite">

    <p><h3>Your survey results will appear here.</h3></p>


    <p></p>
    <a name="ShowResults" id="ShowResults"></a>

    </div> <!-- Results -->

    <div id="footer">

      <p>&nbsp;</p>
      
      </div> <!-- Footer -->

        
    </div> <!-- Container -->


    </body>

    </html>

  4. #4
    Join Date
    Aug 2014
    Posts
    6
    i cant post full codes here because it over 10000 words. that's why i put at attachment at my older post above.
    my php file only display the test question while the javascript used to count the marks and generate result. i do not know how to put the result into database. Can you help me?

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    853
    WHICH is why I asked for what I asked for....

    What does that mean - "I do not know how to put the result into the database"? You don't know any sql or how to connect to your db?

    And - HOW could you write 100000 'words' of code and not be able to update a db yet? Unless you didn't write this code but merely took it and now you want US to debug it for you?
    Last edited by ginerjm; 08-13-2014 at 01:32 PM.

  6. #6
    Join Date
    Aug 2014
    Posts
    6
    I am sorry for misunderstood for your post.

    actually my codes above work perfectly to display the result. And of course I know how to connect to database.

    because of my limited knowledge, I took a codes from internet that work perfectly like I want. However, because of the codes to count the marks is in javascript, I does not know how to save the result generate by javascript into database. I only know that javascript cant use to save data into database. Thats why I want to ask, if there any way to the result into php var, so that I can save into database. Sorry again for any inconvenience. Thank you.

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    853
    Use your js code to store the count value into a hidden input tag and then let your php grab it from the $_POST array and add it to the query just like any other inputs

  8. #8
    Join Date
    Aug 2014
    Posts
    6
    can you give an example on how to set a hidden input tag in js and grab that value by php?
    I am a little bit confused.

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    853
    Since you have taken the responsibility of managing 100,000+ lines/words of code with this project, I'll let you teach yourself how to add a hidden input field to your form. A Very Basic Step. Once you have done that Show Us The Complete Form ONLY and we'll go to the next step.

  10. #10
    Join Date
    Aug 2014
    Posts
    6
    did you mean this is hidden input field?
    <input type="hidden" id="ans1" name="ans1">

    since i have 18 question, then should i put this code at every answer of my question or at the submit button?
    what did you mean by "Show Us The Complete Form ONLY"? the image of my form or the codes.
    Attached Images Attached Images

  11. #11
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    853
    You said you needed a count value passed. I assume that means one field is needed to hold that count.

    Showing the form means "show the form code". We have no use for an image of your form. We are coders, not art critics.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles