Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP和jQuery进行单选按钮测验_Php_Jquery_Html_Yahoo_Bing - Fatal编程技术网

使用PHP和jQuery进行单选按钮测验

使用PHP和jQuery进行单选按钮测验,php,jquery,html,yahoo,bing,Php,Jquery,Html,Yahoo,Bing,我正在尝试使用单选按钮进行测验,但我不知道如何在单击按钮后发布答案。我在代码末尾添加了一些注释,我在其中解释了这一点。 <!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://ajax.googleap

我正在尝试使用单选按钮进行测验,但我不知道如何在单击按钮后发布答案。我在代码末尾添加了一些注释,我在其中解释了这一点。

    <!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
</head>
<body>

<?php
echo "<b> QUIZZZ!!!!! </b> <br>";
echo "----------------------------------------------------------------<br>";
 $k=1;
 $filmat = array("Horror","Aksion","Komedi","Romance","Thriller","Fantazi");
for ($i=0; $i <=5 ; $i++) { 

    echo "$k) Do u like  {$filmat[$i]} movies?";// willl genearate questions from  1->6
    echo "<br>";
    echo"<input type='radio' id='butonYes$k'>Yes";// will generate buttons with  id from 1->6
    echo "<br>";
    echo "<input type='radio' id='butonNo$k'> No";$k++;
    echo "<br>";
}

echo "----------------------------------------------------------------<br>";
echo "the films u selected are: <br>";

// here i want some jquery or php code to print the question with which genere of movies are clicked 
//for exaple i want just to print
/*
Horror
Aksion
Fantazi
*/
// if there are the only ones that are cliked yes
//pls help
?>
</body>
</html>


要实现这一目标,您应该考虑以下几点。首先,需要将输入元素包装到表单标记中。然后在显示结果之前检查页面是否有POST数据。无线电输入标签最好是按其名称属性分组,而不是所有标签都具有唯一ID

<?php
    echo "<b> QUIZZZ!!!!! </b> <br>";
    echo "----------------------------------------------------------------<br>";
    echo "<form method='POST' action=''>";
    $k=1;
    $filmat = array("Horror","Aksion","Komedi","Romance","Thriller","Fantazi");
        for ($i=0; $i <=5 ; $i++) { 
            echo "$k) Do u like  {$filmat[$i]} movies?";// willl genearate questions from  1->6
            echo "<br>";
            echo"<input type='radio' name='{$filmat[$i]}' value='yes'>Yes";// will generate buttons with  id from 1->6
            echo "<br>";
            echo "<input type='radio' name='{$filmat[$i]}' value='no'> No";$k++;
            echo "<br>";
    }
    echo "<input type='submit'>";
    echo "</form>";
    echo "----------------------------------------------------------------<br>";
    echo "the films u selected are: <br>";

    // do something with the results here
    if(isset($_POST) && !empty($_POST)) {
        echo "<pre>;";
        print_r($_POST);
    }
?>

谢谢,我使用了表单和if(isset($\u POST)&&&&!empty($\u POST))打印我的答案,我使用了下面的代码:if(isset($\u POST['submit'])&&&&!empty($\u POST)){for($i=1;$i