Coding Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

Coding Problem

Post 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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Re: Coding Problem

Post by thomas777neo »

On dummy2.php, get your values send using $_POST or $_REQUEST and populate it into a SQL query.
Post Reply