0

所以.. 我有一个上传页面,我可以上传一个充满数据的 xml 表。我在页面本身上处理它(在页面关闭后它被删除后不发送到任何数据库)我不知道每次将上传多少行但它不应该大于 100。

现在,我得到了这部分,作为一个可以上传所有数据的表单,用户需要在为每一行创建的单选按钮中选择一个值(单选按钮的值:1-5):

<form enctype="multipart/form-data" name="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onsubmit="return checkForm()">
    <?php $numRow=0;?>
    <?php //echo "<input type='radio' name='difficulty".$numRow."' value='11'>11";?>
    <table border="1">
        <tr> 
            <th>table of all courses</th> 
        </tr> 
        <?php $data[0]['Points']="נז";?>
        <?php foreach( $data as $row ) { ?> 
        <tr> 
            <td><?php echo( $row['Year'] ); ?></td>
            <td><?php echo( $row['Semester'] ); ?></td>
            <td><?php echo( $row['Code'] ); ?></td>   
            <td><?php echo( $row['Course'] ); ?></td> 
            <td><?php echo( $row['Points'] ); ?></td> 
            <td><?php echo( $row['Grade'] ); ?></td>
            <td><?php if ($numRow > 0)
                    {
                        for($choise=1;  $choise<6;  $choise++)
                        {
                            echo "<input type='radio' name='difficulty".$numRow."' value='".$choise."'>".$choise."&nbsp;&nbsp;&nbsp;";
                        }
                    }
                ?>
            </td>
        </tr> 
        <?php $numRow++;                }$numRow--; ?> 
    </table> 
    <input name="next" type="submit" value="continue" onclick="return true;">
    </form>

它工作得很好,并且每行上的单选按钮都有不同的值,但问题是,我该如何处理?我在考虑也许将所有挑选的 raio 按钮值发送到一个数组?

这部分我也进入了同一页面,因为在用户选择了所有内容之后:

<?php 

    if(isset($_POST['next']) ) 
    { 
        if(isset($_POST['difficulty2']))
            $difficulty2 = $_POST['difficulty2'];
                    else
            $difficulty2="";
        if(isset($_POST['difficulty1']))
            $difficulty1 = $_POST['difficulty1'];
        else
            $difficulty1="";
        echo "User Has submitted the form and entered this difficulty1 : <b> $difficulty1 </b></br>";
        echo "User Has submitted the form and entered this difficulty2 : <b> $difficulty2 </b></br>";           
    }

    else
    {
?>

我可以得到这样的值,但是有没有比只检查有多少行并循环在数组中添加所有 POST 更清洁、更快的方法?我希望我说清楚了,感谢您的帮助:P

4

2 回答 2

0

尝试:

echo '<input type="radio" name="difficulty['.$numrow.']" value="'.$choise.'" />';

然后 $_POST['difficulty'] 将是一个由行号索引的数组,其值为所选选项。

于 2013-04-22T10:44:15.670 回答
0
for($choise=1;  $choise<6;  $choise++)
{
    echo "<input type='radio' name='difficulty[".$numRow."]' value='".$choise."'>".$choise."&nbsp;&nbsp;&nbsp;";
}

然后

$difficulty = isset($_POST['difficulty'])?$_POST['difficulty']:'';

echo "User Has submitted the form and entered this difficulty1 : <b> {$difficulty[0]} </b></br>";
echo "User Has submitted the form and entered this difficulty2 : <b> {$difficulty[1]} </b></br>"; 

评论

action="<?php echo $_SERVER['PHP_SELF']?>"

这对 xss 不利

于 2013-04-22T10:35:57.327 回答