动态html表单值未存储在数据库中

问题描述:

我正在开发一个游戏门户,教授应该可以在其中添加任何类型的问题.我已经在form.php中创建了问题类型(多项选择或描述性)函数,我在主文件中调用了它们.首先,在循环中,我调用主框(简单的html框),在其中必须添加问题.并且它的工作正常.现在,我必须将动态更改的框值存储在数据库中.但是我不知道我在哪里错.以下是我的form.php,在其中我要创建要在主文件中调用的表单.

I am developing a game portal in which professor should be able to add any type of questions in a game. I have created the question type(multiple choice or descriptive ) functions in form.php and i am calling them in my main file. First of all in the loop I am calling main box(simple html box) in which i have to add the question. And its working fine. Now i have to store the dynamically changed boxes values in database. But i don't know where i am wrong. Following is my form.php in which i am creating forms to call in the main file.

    <?
    $i=$_post['i'];
    $_SESSION["input_type"][$i]= $_POST["type"];
    if($_SESSION["input_type"][$i]==1)
    {
    form($i);
    }
    elseif($_SESSION["input_type"][$i]==2)
    {
    form1();
    }

    function form($i)
    {

    ?>

    <div class="control-group">
    <div class="controls">
    <textarea class="large m-wrap"   placeholder=" Statement " cols="50"rows="3" name="statement<?echo $i;?>"  style="text-align:center;" id="statement<?echo $i;?>"></textarea>
    </div>
    </div>
    <div class="name">
    <input name="option<?echo $i.'1';?>" id="option<?echo $i.'1';?>"   placeholder="Option 1" style="width:170px;" type="text"/>

    <input name="option<?echo $i.'2';?>" id="option<?echo $i.'2';?>"    type="text" style="width:170px;" placeholder="Option 2"/>

    <input name="option<?echo $i.'3';?>" id="option<?echo $i.'3';?>"  type="text" style="width:170px;" placeholder="Option 3"/>

    <input name="option<?echo $i.'4';?>" id="option<?echo $i.'4';?>" type="text" style="width:170px;" placeholder="Option 4"/>

    </div>
    <div class="control-group">
    <div class="controls">
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    <label class="radio">
    <input type="radio" name="option<?echo $i.'1';?>_default" id="option<?echo $i.'1';?>_default" />
    Option 1
    </label>
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    <label class="radio">
    <input type="radio" name="option<?echo $i.'2';?>_default" id="option<?echo $i.'2';?>_default" checked />
    Option 2
    </label>  
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    <label class="radio">
    <input type="radio" name="option<?echo $i.'3';?>_default" id="option<?echo $i.'3'?>_default" />
    Option 3
    </label> 
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    <label class="radio">
    <input type="radio" name="option<?echo $i.'4';?>_default" id="option<?echo $i.'4';?>_default" />
    Option 4
    </label>
    </div>
    </div>

    <?php
    }
    //end
    ?>

   <?php
   function form1()
   { ?>

   <div class="control-group" id ="field" name="field">
   <label class="control-  label">Answer</label>
   <div class="controls">
   <input type="text" placeholder="Answer" id ="ans" name="ans" class="m-wrap small" />
                               </div>
                            </div>
        <?
      }
    ?>

这是我在其中的主文件,其中包含form.php函数以添加问题

This is my main file in which i am cakking the form.php functions to add questions

            <!-- BEGIN PAGE -->
     <div class="page-content">
     <form action="storeGame.php" method="POST">
     <div class="control-group">

      <label class="control-label">Game Name</label>
      <div class="controls">
      <input type="text" id="game_name" name="game_name" placeholder="Enter Game Name" class="m-wrap large" />
      </div>
      </div>        

     <!-- BEGIN BORDERED TABLE PORTLET-->

     <?
        $q_no=5;
        for ($i=0;$i<$_SESSION["q_inc"]; $i++)
        {
        ?>
       <div class="portlet box yellow">
                    <div class="portlet-title">
                        <h4><i class="icon-coffee"></i>#<?echo $i+1;?>         </h4>
                        <div class="tools">
                            <a href="javascript:;" class="collapse"></a>
                            <a href="#portlet-config" data-toggle="modal"                      class="config"></a>
                            <a href="javascript:;" class="reload"></a>
                            <a href="javascript:;" class="remove"></a>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <table class="table table-bordered table-hover">
                            <thead>

                            </thead>
                            <tbody>
            <form action="newGame.php" method="POST" id="input_type" name="input_type">
           <div class="control-group">
                               <label class="control-label"  > Add Input</label>
                               <div class="controls">
                                  <select  class="medium m-wrap question_type" data-question-no="<?echo $i;?>" tabindex="1" id="type<?echo $i;?>" name="type<?echo $i;?>">
                                  <option value="">Input Type</option>
                                     <option value="1">Multiple Choice</option>
                                     <option value="2">Input Field</option>
                                  </select>
                               </div>
                               <div id="answer_no_<?php echo $i ?>"></div>
                            </div>
    </form>

                            </tbody>
                        </table>
                    </div>
                </div>

    <script>
    $(document).ready(function(){
        $('.question_type').change(function(){
            var question_no=$(this).attr('data-question-no');
            $.ajax({
                url: "form.php",
                type:'post',
                data:{
                    type:$(this).val(),
                    i:question_no
                },
                success:function(data){
                    $('#answer_no_'+question_no).html(data);
                }

           });
    });
    });
    </script>
                    <?
                    }

             ?>

                    <!-- END BORDERED TABLE PORTLET-->

        <!-- BEGIN PAGE CONTAINER-->
        <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
            <div class="row-fluid">
                <div class="span12">
                    <!-- BEGIN STYLE CUSTOMIZER -->
                    <div class="color-panel hidden-phone">
                        <div class="color-mode-icons icon-color"></div>
                        <div class="color-mode-icons icon-color-close"></div>
                        <div class="color-mode">
                            <p>THEME COLOR</p>
                            <ul class="inline">
                                <li class="color-black current color-default" data-style="default"></li>
                                <li class="color-blue" data-style="blue"></li>
                                <li class="color-brown" data-style="brown"></li>
                                <li class="color-purple" data-style="purple"></li>
                                <li class="color-white color-light" data-style="light"></li>
                            </ul>
                            <label class="hidden-phone">
                            <input type="checkbox" class="header" checked value="" />
                            <span class="color-mode-label">Fixed Header</span>
                            </label>                            
                        </div>
                    </div>
                    <!-- END BEGIN STYLE CUSTOMIZER --> 
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->           
                    <h3 class="page-title">

                    </h3>

                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->

            <div class="row-fluid">
                <div class="span12" >

                <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="POST" >
                <input type="hidden" id="session" data="@Request.RequestContext.HttpContext.Session['questNo']" />
            <!--    <a  class="btn green"  type="submit" ><i class="icon-plus" ></i></a> -->
            <button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>
                                    </form>

            </div>
            <!-- END PAGE CONTENT-->
        </div>
        <!-- END PAGE CONTAINER-->  
        <button type="submit" class="btn yellow btn-block" id="getGames" name="getGames" class="btn green">Create Game    <i &nbsp class="m-icon-big-swapright m-icon-white"></i></button>                  
                </form>
                </div>
    </div>
    <!-- END PAGE -->

下面是我的storeGame.php文件,其中我正在获取问题字段的值并将其保存在数据库中,但未保存动态框值,但正在保存所有其他框值.

And below is my storeGame.php file in which i am getting values of question fields and saving in the database but the dynamic box values are not being saved but all other box values are being saved.

    <?
    session_start();
    include_once("../Includes/db_connection.php");
    $lecturer_id = $_SESSION["lecturer_id"];
    $game_name=mysql_real_escape_string($_POST['game_name']);
    echo $_SESSION["lecturer_id"];;
    echo $game_name;
    mysql_query("insert into games(game_name, lecturer_id) values ('$game_name', '$lecturer_id')");
    for($i=0;$i<$_SESSION["q_inc"];$i++)
    {
      $input_type = mysql_real_escape_string($_POST['type'.$i]);
      if($input_type=='1') 
      {
      $question= $_POST['statement'.$i];
      $val1= $_POST['option'.$i.'1'];
      $val2= $_POST['option'.$i.'2'];
      $val3= $_POST['option'.$i.'3'];
      $val4= $_POST['option'.$i.'4'];
      $default1= $_POST['option'.$i.'1'.'_default'];
      $default2= $_POST['option'.$i.'2'.'_default'];
      $default3= $_POST['option'.$i.'3'.'_default'];
      $default4= $_POST['option'.$i.'4'.'_default'];
      mysql_query("insert into subgames(game_id, input_id, statement, option1, option2, option3, option4, default1, default2, default3, default4) values ((SELECT id 
     FROM games WHERE game_name = '$game_name'), '$input_type', '$question', '$val1', '$val2', '$val3', '$val4', '$default1', '$default2', '$default3', '$default4')");
     $error= mysql_error();
     }
     elseif($input_type=='2')
     {
     $question= $_POST['quest'];
     $answer= $_POST['ans'];
     // it is not implemented so leave it
     }

     }

请帮助我,我已经尝试了很多,但是我不知道我在哪里错了.预先感谢

Kindly help me i have tried a lot but i don't know where i am wrong. Thanks in advance

首先,我想告诉您代码中存在很多问题.我得到的如下.

First of all I want to tell you that there are lots of problem in your code. Those I got are as follows.

1:无需粘贴整个HTML代码的页眉和页脚.这会导致无法给您提供答案的人员跳过,他们在看到大量代码后便逃走了.即不必要.

1: There is no need to paste the entire html code of header and footer as well. This causes to skipped from the people who can give you answer, they run away after seeing lots of code. i.e. unnecessary.

2 :您已经定义了多个表单标签,并且这些表单彼此嵌套.在打开任何其他表单标签之前,应关闭所有表单.

2: You have defined multiple form tags, and these forms are nested to each other. every form should be closed before opening any other form tag.

3 :单选按钮标签的名称对于每个选项组应该相同,其值应与名称不同.例如,对于性别,应该有两个名称相同的收音机输入标签,名称为name ="gender",而值分别为value ="male"& value ="female".您将获得具有相同名称的单选按钮的唯一一个值.

3: Radio button tag's name should have the same for every group of the option, their value should be different not the name. for example for gender there should be two radio input tag with same name name="gender" and with different value like value="male" & value="female". you'll get the only one value for the radio button with same name.

4::如果您打算在页面上的任何位置使用会话,则应首先启动会话,然后再打印任何输出.

4: if you are going to use session anywhere on the page, it first of all should be started before printing any output.

5 :您尚未为单选按钮的默认值提供任何值.所以里面应该有一个值属性不同的值

5: You have not given any value for the default value of radio button. So there should be a value attribute with different value inside that

6::每当要命名功能时,请根据其功能进行命名,而不是像a,b,c.在这里,我要将您的表单更改为form_multiple(),将form1更改为form_input()

6: whenever you are going to name a funtion, name it according to its functionality, not like a, b, c. Here I'm going to change your form to form_multiple() and form1 to form_input()

7::当您要为多个问题选择输入字段时,将有两个名称相同的输入字段,这是不允许的.因此,这里也将i传递给函数.

7: when you are going to choose input field for more than one question, then you'll have two input field with the same name, that is not allowed. So, let here also pass the i to the function.

===================

====================

这是您的代码解决方案.

1::我已将单选按钮中的数字从默认值中删除.

1: I have removed the numbers from default in radio button.

<?php
$i = $_POST['i'];
$_SESSION["input_type"][$i] = $_POST["type"];
if ($_SESSION["input_type"][$i] == 1) {
    form_multiple($i);
} elseif ($_SESSION["input_type"][$i] == 2) {
    form_input($i);
}

function form_multiple($i)
{
    ?>
    <div class="control-group">
        <div class="controls">
            <textarea class="large m-wrap" placeholder=" Statement " cols="50" rows="3" name="statement<?php echo $i; ?>" style="text-align:center;" id="statement<?php echo $i; ?>"></textarea>
        </div>
    </div>
    <div class="name">
        <input name="option<?php echo $i . '1'; ?>" id="option<?php echo $i . '1'; ?>" placeholder="Option 1"
               style="width:170px;" type="text"/>

        <input name="option<?php echo $i . '2'; ?>" id="option<?php echo $i . '2'; ?>" type="text" style="width:170px;"
               placeholder="Option 2"/>

        <input name="option<?php echo $i . '3'; ?>" id="option<?php echo $i . '3'; ?>" type="text" style="width:170px;"
               placeholder="Option 3"/>

        <input name="option<?php echo $i . '4'; ?>" id="option<?php echo $i . '4'; ?>" type="text" style="width:170px;"
               placeholder="Option 4"/>

    </div>
    <div class="control-group">
        <div class="controls">
            Choose Default Option
            <br/>
            <label class="radio">
                <input type="radio" value="1" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '1'; ?>_default"/>
                Option 1
            </label>
            <br/>
            <label class="radio">
                <input type="radio" value="2" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '2'; ?>_default"
                       checked />
                Option 2
            </label>
            <br/>
            <label class="radio">
                <input type="radio" value="3" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '3' ?>_default"/>
                Option 3
            </label>
            <br/>
            <label class="radio">
                <input type="radio" value="4" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '4'; ?>_default"/>
                Option 4
            </label>
        </div>
    </div>
<?php
}
//end
?>

<?php
function form_input($i)
{
    ?>
    <div class="control-group" id="field" name="field">
        <label class="control-  label">Answer</label>
        <div class="controls">
            <input type="text" placeholder="Answer" id="ans" name="ans_<?php echo $i; ?>" class="m-wrap small"/>
        </div>
    </div><?php
}
?>

===================================

=====================================

在下一页中,我删除了一些标签以缩短答案 而且我也评论了表单标签,以便您分析错误.这两个表格位于另一个表格标签中 我不知道您在哪里定义了$_SESSION["q_inc"]变量.我假设此变量内部将具有一些整数值.

In the below page I have removed some of the tags to shorten the answer and I also have commented the form tags, so that you can analyze your errors. These two forms were inside another form tag I don't know where you have defined $_SESSION["q_inc"] variable. I assume that this variable will have some integer value inside.

    <?php
session_start();
include_once("../Includes/db_connection.php");
//include_once("form.php");
if(isset($_POST['total_q'])){
$_SESSION["q_inc"]=$_POST['total_q'];
}
if (!isset($_SESSION["q_inc"])) {
    $_SESSION["q_inc"] = 2;
}

$_SESSION["questNo"] = $_SESSION["q_inc"];
if (!isset($_SESSION["lecturer_id"])) {
    header("Location:../login.php");
}
//if($_SERVER['add_q'] == 'POST')
//$counter=0;


if (isset($_POST['add_q'])) {
    $_SESSION["q_inc"]++;
}

?>
<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <script type="text/javascript" src="../includes/jquery.js"></script>


    <meta charset="utf-8"/>
    <title>ClassEx</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <link href="../assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../assets/css/metro.css" rel="stylesheet"/>
    <link href="../assets/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"/>
    <link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet"/>
    <link href="../assets/fullcalendar/fullcalendar/bootstrap-fullcalendar.css" rel="stylesheet"/>
    <link href="../assets/css/style.css" rel="stylesheet"/>
    <link href="../assets/css/style_responsive.css" rel="stylesheet"/>
    <link href="../assets/css/style_default.css" rel="stylesheet" id="style_color"/>
    <link rel="stylesheet" type="text/css" href="../assets/chosen-bootstrap/chosen/chosen.css"/>
    <link rel="stylesheet" type="text/css" href="../assets/uniform/css/uniform.default.css"/>
    <link rel="shortcut icon" href="../assets/img/favicon.ico"/>

</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="fixed-top">
<!-- BEGIN HEADER -->
<div class="header navbar navbar-inverse navbar-fixed-top">
    <!-- BEGIN TOP NAVIGATION BAR -->
    <div class="navbar-inner">
        <div class="container-fluid">
            <!-- BEGIN LOGO -->
            <a class="brand" href="#">
                <img src="../assets/img/logoclassex.jpg" alt="logo" height="35px" width="35px""/>
            </a>
            <!-- END LOGO -->
            <!-- BEGIN RESPONSIVE MENU TOGGLER -->
            <a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
                <img src="../assets/img/menu-toggler.png" alt=""/>
            </a>
            <!-- END RESPONSIVE MENU TOGGLER -->
            <!-- BEGIN TOP NAVIGATION MENU -->
            <ul class="nav pull-right">


                <!-- BEGIN NOTIFICATION DROPDOWN -->

                <!-- END NOTIFICATION DROPDOWN -->
                <!-- BEGIN INBOX DROPDOWN -->

                <!-- END INBOX DROPDOWN -->
                <!-- BEGIN TODO DROPDOWN -->

                <!-- END TODO DROPDOWN -->

            </ul>
            <!-- END TOP NAVIGATION MENU -->
        </div>
    </div>
    <!-- END TOP NAVIGATION BAR -->
</div>
<!-- END HEADER -->
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
    <!-- BEGIN SIDEBAR -->
    <div class="page-sidebar nav-collapse collapse">
        <!-- BEGIN SIDEBAR MENU -->
        <ul>
            <li>
                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
                <div class="sidebar-toggler hidden-phone"></div>
                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
            </li>

            <li class="start ">
                <a href="lecturer.php">
                    <i class="icon-home"></i>
                    <span class="title">Dashboard</span>
                </a>
            </li>


            <li class="">
                <a href="../includes/logout.php">
                    <i class=" icon-off"></i>
                    <span class="title">Logout</span>
                </a>
            </li>
        </ul>
        <!-- END SIDEBAR MENU -->
    </div>
    <!-- END SIDEBAR -->
    <!-- BEGIN PAGE -->
    <div class="page-content">
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="POST" >
            <input type="hidden" id="session" data="@Request.RequestContext.HttpContext.Session['questNo']" />
            <!--    <a  class="btn green"  type="submit" ><i class="icon-plus" ></i></a> -->
            Enter no of question<input name="total_q" type="text" />
            <input type="submit" />
            <!--<button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>-->
        </form>
        <form action="storeGame.php" method="POST">
            <div class="control-group">
                <label class="control-label">Game Name</label>

                <div class="controls">
                    <input type="text" id="game_name" name="game_name" placeholder="Enter Game Name"
                           class="m-wrap large"/>
                </div>
            </div>
            <!-- BEGIN BORDERED TABLE PORTLET-->
            <?php
            $q_no = 5;
            for ($i = 0; $i < $_SESSION["q_inc"]; $i++) {
                $temp = $i;
                ?>
                <div class="portlet box yellow">
                    <div class="portlet-title">
                        <h4><i class="icon-coffee"></i>#<?php echo ($temp + 1); ?></h4>

                        <div class="tools">
                            <a href="javascript:;" class="collapse"></a>
                            <a href="#portlet-config" data-toggle="modal" class="config"></a>
                            <a href="javascript:;" class="reload"></a>
                            <a href="javascript:;" class="remove"></a>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <table class="table table-bordered table-hover">
                            <div class="control-group">
                                <label class="control-label"> Add Input</label>

                                <div class="controls">
                                    <select class="medium m-wrap question_type" data-question-no="<?php echo $i; ?>"
                                            tabindex="1" id="type<?php echo $i; ?>" name="type<?php echo $i; ?>">
                                        <option value="">Input Type</option>
                                        <option value="1">Multiple Choice</option>
                                        <option value="2">Input Field</option>
                                    </select>
                                </div>
                                <div id="answer_no_<?php echo $i; ?>"></div>
                            </div>
                            </tbody>
                        </table>
                    </div>
                </div>
            <?php
            }
            ?>
            <script>
                $(document).ready(function () {
                    $('.question_type').change(function () {
                        var question_no = $(this).attr('data-question-no');
                        $.ajax({
                            url: "form.php",
                            type: 'post',
                            data: {
                                type: $(this).val(),
                                i: question_no
                            },
                            success: function (data) {
                                $('#answer_no_' + question_no).html(data);
                            }

                        });
                    });
                });
            </script>
            <!-- END BORDERED TABLE PORTLET-->

            <!-- BEGIN PAGE CONTAINER-->
            <div class="container-fluid">

                <!-- BEGIN PAGE CONTENT-->

                <div class="row-fluid">
                    <div class="span12">

                        <!--                    <form action="-->
                        <?php //echo $_SERVER['PHP_SELF']; ?><!--"  method="POST" >-->
                        <!--                        <input type="hidden" id="session" data="@Request.RequestContext.HttpContext.Session['questNo']" />-->
                        <!--                        <button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>-->
                        <!--                    </form>-->

                    </div>
                    <!-- END PAGE CONTENT-->
                </div>
                <!-- END PAGE CONTAINER-->
                <button type="submit" class="btn yellow btn-block" id="getGames" name="getGames" class="btn green">
                    Create Game <i &nbsp class="m-icon-big-swapright m-icon-white"></i></button>
        </form>
    </div>
</div>
<!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<div class="footer">
    University of Passau ClassEx Team
    <div class="span pull-right">
        <span class="go-top"><i class="icon-angle-up"></i></span>
    </div>
</div>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS -->
<!-- Load javascripts at bottom, this will reduce page load time -->
<script src="../assets/js/jquery-1.8.3.min.js"></script>
<script src="../assets/breakpoints/breakpoints.js"></script>
<script src="../assets/jquery-slimscroll/jquery-ui-1.9.2.custom.min.js"></script>
<script src="../assets/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/js/jquery.blockui.js"></script>
<script src="../assets/js/jquery.cookie.js"></script>
<script src="../assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
<script type="text/javascript" src="../assets/uniform/jquery.uniform.min.js"></script>
<script type="text/javascript" src="../assets/chosen-bootstrap/chosen/chosen.jquery.min.js"></script>
<!-- ie8 fixes -->
<!--[if lt IE 9]>
<script src="../assets/js/excanvas.js"></script>
<script src="../assets/js/respond.js"></script>
<![endif]-->
<script src="../assets/js/app.js"></script>
<script>
    jQuery(document).ready(function () {
        // initiate layout and plugins
        App.setPage('calendar');
        App.init();
    });
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>

==============================

===============================

数据库中应该只有一个默认选项字段.在这里,我删除了所有这些,并添加了一个名为"default_option"

There should be only one default option field in the database. Here I have removed all those and added one named "default_option"

    <?php
session_start();
include_once("../Includes/db_connection.php");
$lecturer_id = $_SESSION["lecturer_id"];
$game_name=mysql_real_escape_string($_POST['game_name']);
echo $_SESSION["lecturer_id"];;
echo $game_name;
$sql="insert into games(game_name, lecturer_id) values ('$game_name', '$lecturer_id')";
if(!mysql_query($sql)){
    echo "Error in storing into database!<br/>";
}

for($i=0;$i<$_SESSION["q_inc"];$i++)
{
    $input_type = mysql_real_escape_string($_POST['type'.$i]);
    if($input_type=='1')
    {
        $question= $_POST['statement'.$i];
        $val1= $_POST['option'.$i.'1'];
        $val2= $_POST['option'.$i.'2'];
        $val3= $_POST['option'.$i.'3'];
        $val4= $_POST['option'.$i.'4'];
        //Here should be only one default value
        $default_option= $_POST['option'.$i.'_default'];
        /*$default1= $_POST['option'.$i.'1'.'_default'];
        $default2= $_POST['option'.$i.'2'.'_default'];
        $default3= $_POST['option'.$i.'3'.'_default'];
        $default4= $_POST['option'.$i.'4'.'_default'];*/
        $sql="  insert into subgames(   game_id,                                                        input_id,       statement,      option1,    option2, option3, option4, default_option)
                             values (   (SELECT id FROM games WHERE game_name = '$game_name' limit 1),  '$input_type',  '$question',    '$val1',    '$val2', '$val3', '$val4', '$default_option')";
        if(!mysql_query($sql)){
            echo "Error";
        }
        else{
            echo "Success";
        }
        //$error= mysql_error();
    }
    elseif($input_type=='2')
    {
        $question= $_POST['quest'];
        $answer= $_POST['ans'];
        // it is not implemented so leave it
    }

}