在PHP上保存单选按钮信息

时间:2015-03-06 12:04:06

标签: php mysql

我正在进行投票项目,我有一个从数据库填充的表单,我设法使用循环生成单选按钮。然而单选按钮只能从可能的八个中选择一个答案,我需要它在每个问题中选择一个答案。我知道单选按钮名称是相同的,需要是不同的,但它是一个循环,所以我不知道如何更改名称。有什么帮助吗?

这是代码

<?php $title="POLLS | Voting - Home";
require_once( "includes/session.php");
include( "includes/connection.php"); 
include( "includes/header.php"); 
$query="SELECT user_id FROM users WHERE user_id={$_SESSION['user_id']}" ;
$result=mysql_query($query,$connection); 
$row=mysql_fetch_row($result);
$_SESSION[ 'user_id']=$row[0]; ?>

<body>
    <div id="outerDiv">
        <div id="header">
            <div id="mainMenu"> </div>
            <!-- mainMenu -->
        </div>
        <!-- header -->
        <div id="midBanner"> </div>
        <div id="content">
            <div id="mainContent">
                <p>Welcome,
                    <?php echo strtoupper($_SESSION[ 'username'])?>!</p>
                <form action="votingpage.php" method="post">
                    <?php $query="SELECT question_id,question FROM questions " ; $result=mysql_query($query, $connection); ?>
                    <form>
                        <table class="Question Table">
                            <th></th>
                            <?php echo "<tr>"; echo "<tr>"; echo "<tr>"; ***strong text***$num_rows="" ; $counter=$num_rows; while($row=mysql_fetch_assoc($result)){ echo "<br />"; $counter +=1 ; echo "<br />"; echo $counter; echo $row[ 'question']; echo "<br />"; $query1="SELECT qstn_ans_id, possible_answer FROM qanswers WHERE question_id= " . $row[ 'question_id'] ; $result1=mysql_query($query1, $connection); while($row1=mysql_fetch_assoc($result1)){ echo "<input type='radio' name='possible_answer'".$row1[ 'qstn_ans_id']. " value='".$row1[ 'qstn_ans_id']. "'/> ".$row1[ 'possible_answer']; echo "<br />"; } } ?> </table>
                    </form>
            </div>
            <!-- mainContent -->
            <p class="clear" /> </div>
        <!-- content -->
    </div>
    <!-- outerDiv -->
    <?php include( "includes/footer.php"); ?>

0 个答案:

没有答案