/    Sign up×
Community /Pin to ProfileBookmark

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.
[ATTACH=CONFIG]16297[/ATTACH]
[ATTACH=CONFIG]16295[/ATTACH]

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 13.2014 — 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.
Copy linkTweet thisAlerts:
@star18authorAug 13.2014 — [code=php]<!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>

[/code]
Copy linkTweet thisAlerts:
@star18authorAug 13.2014 — 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?
Copy linkTweet thisAlerts:
@ginerjmAug 13.2014 — 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?
Copy linkTweet thisAlerts:
@star18authorAug 13.2014 — 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.
Copy linkTweet thisAlerts:
@ginerjmAug 13.2014 — 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
Copy linkTweet thisAlerts:
@star18authorAug 13.2014 — 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.
Copy linkTweet thisAlerts:
@ginerjmAug 14.2014 — 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.
Copy linkTweet thisAlerts:
@star18authorAug 14.2014 — 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.

[canned-message]attachments-removed-during-migration[/canned-message]
Copy linkTweet thisAlerts:
@ginerjmAug 14.2014 — 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.
×

Success!

Help @star18 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...