Page 1 of 1

Coding Problem

Posted: Tue Mar 18, 2008 7:39 am
by tabatsoy
Greetings Earthlings!!!
help me with the code please, all i want is when i press the submit button it will be linked to another page and still it can add my data in the database.
here is my code:

Code: Select all

<?
$db = mysql_connect("localhost");
    mysql_select_db("examination",$db); 
 
 
echo '<FORM name ="form1" method ="post" action ="dummy2.php">
 <table width="800" border="0"  align="center" class="underresult">';
 
        $query = "SELECT *
                FROM logicQuestions";
        $result = mysql_query($query);
        for($i = 0; $i < mysql_num_rows($result); $i++){
            $question_number_logic ++;
            $question = mysql_result($result, $i, "question");
            $choiceA = mysql_result($result, $i, "choiceA");
            $choiceB = mysql_result($result, $i, "choiceB");
            $choiceC = mysql_result($result, $i, "choiceC");
            $choiceD = mysql_result($result, $i, "choiceD");
            $answer = mysql_result($result, $i, "answer");
            echo '<tr>
                    <td></td>';
                '</tr>';
            echo '<tr>
                    <td>&nbsp;</td>';
                '</tr>';
                
            echo '<tr>
                    <td width = "20" align = "left" valign = "top"><font class = "questions">'.$question_number_logic.'.</span><td>';
                    echo '<td width = "280" align = "left" valign = "top" ><font class = "questions">'.$question.'</span></td>';        
                    echo '<td width = "125" align = "left" valign = "center" >&nbsp;</td>';
                    echo '<td width = "125" align = "left" valign = "center" >&nbsp;</td>';
                    echo '<td width = "125"align = "left" valign = "center" >&nbsp;</td>';
                    echo '<td width = "125" align = "left" valign = "center" >&nbsp;</td></tr>';
                    
            echo '<tr>
                    <td>&nbsp;</td>';
                '</tr>';
            
                    
            echo '<tr>
                    <td width = "20" align = "left" valign = "top"><td>';
                    echo '<td width = "280" align = "left" valign = "center" >&nbsp;</td>';     
                    echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number_logic.'" type="radio" value="'.$choiceA.'" />'.$choiceA.'</span></td>';
                    echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number_logic.'" type="radio" value="'.$choiceB.'" />'.$choiceB.'</span></td>';
                    echo '<td width = "125"align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number_logic.'" type="radio" value="'.$choiceC.'" />'.$choiceC.'</span></td>';
                    echo '<td width = "125" align = "left" valign = "center" ><font class = "style1"><input name="'.$question_number_logic.'" type="radio" value="'.$choiceD.'" />'.$choiceD.'</span></td></tr>';
            
            echo '<tr>
                    <td colspan = "7" class = "exam">
&nbsp;</td>
                </tr>';
                $selected_radio = $_POST[$question_number_logic];
    if ($selected_radio == $answer) {
        $score ++;
    }
}
            '</table>
<br /><br />';
echo '<table width="240" border="0" align="center" class="session">
  <tr>';
$result = mysql_query("update dummy set score = '".$score."'
                        where firstname = 'joseph'");
 
echo '<Input type = "Submit" Name = "Submit" VALUE = "Submit">
  </tr>
</FORM>';
?>
 
 
thanks in advance

Re: Coding Problem

Posted: Wed Mar 19, 2008 9:01 am
by thomas777neo
On dummy2.php, get your values send using $_POST or $_REQUEST and populate it into a SQL query.