duanke9540 2014-09-13 10:55
浏览 40

如何使用PHP以html格式从多个单选按钮中获取所选值

I am new to PHP. I am developing an online examination system. In an HTML page I have arranged questions and for selecting answers I have used four radio buttons for 4 options. Similarly for all the 20 questions. Now what is problem with this is. I want to get the selected value from radio buttons and i want to store it in avariable and i need to calculate the score i.,e no of correct options. Finally i want to store it into database. Can anyone please give me the example code to do this... this is my html code

<html>
<head>
<body>

<font size=+1 color=blue><u><h1>C Language exam</h1></u></font><p>
<form  method="POST" action="validate1.php">
<pre>
<font face="verdana">


1.In C, if you pass an array as an argument to a function, what actually gets passed?
<p>
<input type=radio name=1 value=a>A. Value of elements in array<br>
<input type=radio name=1 value=b>B. First element of the array<br>
<input type=radio name=1 value=c>C. Base address of the array<br>
<input type=radio name=1 value=d>D. Address of the last element of array<br>



2.How will you print 
 on the screen?<p>
<input type=radio name=2 value=a>A. printf("
");<br>
<input type=radio name=2 value=b>B. echo "\
";<br>
<input type=radio name=2 value=c>C. printf('
');<br>
<input type=radio name=2 value=d>D. printf("\
");<br>



3.C  is what type of language?<p>
<input type=radio name=3 value=a>A. Low leval language<br>
<input type=radio name=3 value=b>B. high level language<br>
<input type=radio name=3 value=c>C. middle level language<br>
<input type=radio name=3 value=d>D. medium language<br>



4.Integer type char storage size.<p>
<input type=radio name=4 value=a>A. 2 bytes<br>
<input type=radio name=4 value=b>B. 1 byte<br>
<input type=radio name=4 value=c>C. 4 byte<br>
<input type=radio name=4 value=d>D. 8 bytes<br>



5.What is the output of given program
#include <stdio.h>  
int main()
 {    /* my first program in C */    
printf("Hello, World! 
");      
  return 0;
 }<p>
<input type=radio name=5 value=a>A. first program<br>
<input type=radio name=5 value=b>B. world<br>
<input type=radio name=5 value=c>C. hello world<br>
<input type=radio name=5 value=d>D. hello<br>



6.How many times the program will print "welcome" ?
#include<stdio.h>
int main()
{
    printf(“welcome”);
    main();
    return 0;
}<p>
<input type=radio name=6 value=a>A. Infinite times<br>
<input type=radio name=6 value=b>B. 32767 times<br>
<input type=radio name=6 value=c>C. 65535 times<br>
<input type=radio name=6 value=d>D. Till stack overflows<br>



7.Symbol of LOGICAL AND operation<p>
<input type=radio name=7 value=a>A. &<br>
<input type=radio name=7 value=b>B. &&<br>
<input type=radio name=7 value=c>C. ><br>
<input type=radio name=7 value=d>D. == <br>



8.What are the different types of real data type in C ?<p>
<input type=radio name=8 value=a>A. float, double<br>
<input type=radio name=8 value=b>B. short int, double, long int<br>
<input type=radio name=8 value=c>C. short int, double, long int<br>
<input type=radio name=8 value=d>D. double, long int, float<br>



9.Which statement will you add in the following program to work it correctly?
#include<stdio.h>
int main()
{
    printf(“%f
”, log(36.0));
    return 0;
}<p>
<input type=radio name=9 value=a>A. #include<conio.h><br>
<input type=radio name=9 value=b>B. #include<math.h><br>
<input type=radio name=9 value=c>C. #include<stdlib.h><br>
<input type=radio name=9 value=d>D. #include<dos.h><br>



10.What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=-3, j=2, k=0, m;
    m = ++i && ++j || ++k;
    printf(“%d,%d,%d,%d
”, i, j, k, m);
    return 0;
}<p>
<input type=radio name=10 value=a>A.  1,2,0,1<br>
<input type=radio name=10 value=b>B. -3,2,0,1<br>
<input type=radio name=10 value=c>C. -2,3,0,1<br>
<input type=radio name=10 value=d>D.  2,3,1,1<br>



11.C closely associated with the which operating system?<p>
<input type=radio name=11 value=a>A. windows<br>
<input type=radio name=11 value=b>B. linux<br>
<input type=radio name=11 value=c>C. unix<br>
<input type=radio name=11 value=d>D. mac<br>



12.C was developed at Bell Laboratories in which year?<p>
<input type=radio name=12 value=a>A. 1943<br>
<input type=radio name=12 value=b>B. 1954<br>
<input type=radio name=12 value=c>C. 1972<br>
<input type=radio name=12 value=d>D. 1975<br>



13.In the following code, the P2 is Integer Pointer or Integer?

Typedef int *ptr;
ptr p1, p2;<p>
<input type=radio name=13 value=a>A. Integer<br>
<input type=radio name=13 value=b>B. Integer pointer<br>
<input type=radio name=13 value=c>C. Error in declaration<br>
<input type=radio name=13 value=d>D. None of above<br>



14.In the following code what is 'P'?
Typedef char *charp;
Const charp P;<p>
<input type=radio name=14 value=a>A. P is a constant<br>
<input type=radio name=14 value=b>B. P is a character constant<br>
<input type=radio name=14 value=c>C. P is character type<br>
<input type=radio name=14 value=d>D. None of above<br>



15.What is the similarity between a structure, union and enumeration?<p>
<input type=radio name=15 value=a>A. All of them let you define new values<br>
<input type=radio name=15 value=b>B. All of them let you define new data types<br>
<input type=radio name=15 value=c>C. All of them let you define new pointers<br>
<input type=radio name=15 value=d>D. All of them let you define new structures<br>



16.How will you free the allocated memory ?<p>
<input type=radio name=16 value=a>A. remove(var-name);<br>
<input type=radio name=16 value=b>B. free(var-name);<br>
<input type=radio name=16 value=c>C. delete(var-name);<br>
<input type=radio name=16 value=d>D. dalloc(var-name);<br>



17.Which header file should be included to use functions like malloc()  and  calloc()?<p>
<input type=radio name=17 value=a>A. memory.h<br>
<input type=radio name=17 value=b>B. stdlib.h<br>
<input type=radio name=17 value=c>C. string.h<br>
<input type=radio name=17 value=d>D. dos.h<br>



18.Specify the 2 library functions to dynamically allocate memory?<p>
<input type=radio name=18 value=a>A. Malloc() and memalloc()<br>
<input type=radio name=18 value=b>B. calloc() and memalloc()<br>
<input type=radio name=18 value=c>C. Malloc() and calloc()<br>
<input type=radio name=18 value=d>D. alloc() and calloc()<br>



19.What are the types of linkages?<p>
<input type=radio name=19 value=a>A. Internal and External<br>
<input type=radio name=19 value=b>B. External, Internal and None<br>
<input type=radio name=19 value=c>C. External and None<br>
<input type=radio name=19 value=d>D. Internal<br>



20.who created the new system's first higher-level language?<p>
<input type=radio name=20 value=a>A. McClure's<br>
<input type=radio name=20 value=b>B. McIlroy<br>
<input type=radio name=20 value=c>C. Thompson's <br>
<input type=radio name=20 value=d>D. Doug McIlroy<br>



<input type="submit" value="submit">
</font>
</pre>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dsfs64664 2014-09-13 11:25
    关注

    Receiving values from the form

    General sample

    $value = $_POST['name'];
    

    Specific code for your situation
    Since you have 18 inputs all named with numbers, you could use:

    for($i=1;$i<19;$i++){
    $value[$i] = $_POST[$i];
    //$value[1] = $_POST['1']
    }
    

    Checking values

    General sample

    if($value=="correctanswer"){$correct++;}
    

    Specific code for your situation

    $correctanswer[1] = "correctanswer1"; //correct answer for input with name 1
    $correctanswer[2] = "correctanswer2";
    //Do this for every input
    for($i=1;$i<19;$i++){
    if($value[$i]==$correctanswer[$i]){$correct++;}
    }
    

    Storing $correct in database

    assuming that you have a table called "correct" with the column "number":

    $connect = mysqli_connect("localhost","root","","db");
    if(!$connect){echo "Couldn't connect.";}
    $query = "INSERT INTO correct(number) VALUES(".$correct.")";
    $execute = mysqli_query($connect,$query);
    if(!$execute){echo "Couldn't execute query. Please open PhpMyAdmin and try to execute the following query: <br>".$query." <br>. If it works, the problem is in the PHP code (or there was a temporary error); otherwise, there's a mistake in the query: please post it as a comment to my answer.";}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式