如何在将临时数据插入数据库MySql(PHP)之前存储它们 [英] How to store temporary data before inserting it to database MySql (PHP)

查看:77
本文介绍了如何在将临时数据插入数据库MySql(PHP)之前存储它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的学校项目进行问卷调查。

我有一个填写表格,这是人们填写姓名,年龄等数据的地方。 br />
然后,我有问题形式,名为music.html和math.html。

如果music.html已被回答,那么它将进入数学.html。

如果两个问卷表格都已被回答,它会显示如下结果:



姓名:John

年龄:20

乐谱:5

数学分数:2



最后,它会将数据(姓名,年龄,乐谱和数学分数)存储到数据库MySql。

我该怎么做?在此先感谢。



Fillform.html

 < ;   html  >  
< head

< / head >
< 表格 姓名 = myform 方法 = post action = 亩ic.html >
用户名:< 输入 名称 = 用户名 type = text > < span class =code-keyword>< br >
年龄:< 输入 name = age type = text > < br >
< 输入 名称 = 按钮 type = 按钮 value = 提交 >
< / body >
< / html <跨度class =code-keyword>>





这里的music.html看起来像:

 <   html  >  
< head >
< script 类型 = text / javascript src = ../ js / script.js > < / script >

< 表格 名称 = myform 方法 = post

önSubmit = return validateRadio() action = math.html >

< c lass = tftable border = 1 >
< tr < span class =code-keyword>> < th > < div align = center class = < span class =code-keyword> tftable th > 问题< / div > < / th > < th colspan = 2 > < div align = center > 答案< / div > < / th >
< / tr >
< tr >
< td > I喜欢跳舞< / td >
< td >

< label >
< input 名称 = bm1< /温泉n> type = radio value = 1 / >
< / label >
< / td >
< td >

< < span class =code-leadattribute> label
>
< input name = bm1 type = radio value = 2 / >

< / label >
< / td >
< span class =code-keyword>< / tr >
< tr >
< span class =code-keyword>< td > 我喜欢玩棒球,足球,曲棍球或足球等运动< / td >
< td >
< label >
< 输入 名称 = bm2 type = radio = 1 / >
< / label >
< / td >
< td >
< 标签 >
< input name = bm2 type = radio value = 2 / >
< / label >
< / td >
< / tr > < / table >





我的math.html在问题上看起来与此类似。

我已经把javascript计算到有多少是答案。如果有4个是那么

乐谱:4

我已经把javascript计算为是答案



script.js

  function  validateRadio()
{
// 获取所有输入类型
var inputs = myform.elements;
var radios = [];

// 找到收音机类型
for var i = 0 ; i< inputs。长度; ++ i){
if (inputs [i] .type == ' radio'){
radios.push(inputs [i]);
}
}
var countChecked = 0 ;
for var j = 0 ; j< radios.length; j ++){
if (radios [j] .checked){
countChecked ++;
}
}
// 带有值= 1的单选按钮的计数/ span>
var answeramount = 0 ;
for var k = 0 ; k< radios.length; k ++){
if (radios [k] .checked&& radios [k] .value = = 1 ){
answeramount ++;
}
}
如果(countChecked!= radios.length / 2 ){
alert( 必须回答所有问题。);
return false ; // abort submit
} else {
alert(answeramount);
return true ; // 继续提交
}
}

解决方案

这不会起作用,只有html和javascript,它没有在哪里。

你必须按顺序包含php代码将页面之间的值传递给其他东西,比如设置Apache服务器和mysql服务器。

要完成这个项目,你必须开始学习PHP+MySQL [ ^ ]

当您在php或mysql编码中遇到问题时,请先询问Google,然后访问CP发布与特定问题相关的问题。

I am making a questionaire for my school project.
I have a "fill-out-form" which is a place for people to fill their data such as name, age, etc.
Then, I have "questionaire form" named "music.html" and "math.html".
If music.html has been answered, then it will go to math.html .
If both of the questionaire forms have been answered, it will show the result like:

Name : John
Age : 20
Music score : 5
Math score : 2

At last, it will store the data (name, age, music score and math score) to database MySql.
How can I do this? Thanks in advance.

Fillform.html

<html>
<head

</head>
<form name="myform" method="post" action="music.html">
    Username	: <input name="username" type="text"> <br>
    Age	        : <input name="age" type="text"> <br>
<input name="Button" type="button" value="SUBMIT">
</body>
</html>



Here's music.html looks like:

<html>
<head>
<script type="text/javascript" src="../js/script.js"></script>

<form name="myform" method="post"

 önSubmit="return validateRadio()" action="math.html">

<table class="tftable" border="1">
<tr><th><div align="center" class="tftable th">Questions</div></th><th colspan="2"><div align="center">Answer</div></th>
</tr>
<tr>
  <td>I like to dance</td>
  <td>

  <label>
  <input name="bm1" type="radio" value="1" />
  Yes</label>
  </td>
  <td>

  <label>
  <input name="bm1" type="radio" value="2" />
  No
  </label>
  </td>
  </tr>
  <tr>
  <td>I like to play sports such as baseball, soccer, hockey, or football </td>
  <td>
  <label>
  <input name="bm2" type="radio" value="1" />
  Yes</label>
  </td>
  <td>
  <label>
  <input name="bm2" type="radio" value="2" />
  No </label>
  </td>
  </tr></table>



My math.html looks same like this just different on the questions.
I have put javascript to count how many "yes" answer are there. If there're 4 yes then
music score : 4
I have put javascript to count the "yes" answer

script.js

function validateRadio()
{
// get all the inputs type
var inputs = myform.elements;
var radios = [];

// find the radio type
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'radio') {
radios.push(inputs[i]);
}
}
var countChecked = 0;
for (var j = 0; j < radios.length; j++) {
if (radios[j].checked) {
countChecked++;
}
}
//count number of radio button with value=1
var answeramount = 0;
for (var k = 0; k < radios.length; k++){
if(radios[k].checked && radios[k].value==1){
answeramount++;
}
}
if (countChecked != radios.length / 2){
alert("All questions must be answered.");
return false; // abort submit
} else {
alert(answeramount);
return true; // proceed to submit
} 
}

解决方案

This is not going to work, only html and javascript, it goes no where.
You have to include php code in order to pass values from page to page, other things like the setting up of an Apache server, and mysql server too.
To accomplish this project, you have to start learning PHP+MySQL[^]
When you encounter problems subsequently in your php or mysql coding, always ask Google first, then visit CP to post questions related to specific issues.


这篇关于如何在将临时数据插入数据库MySql(PHP)之前存储它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆