Page 1 of 1

Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:20 am
by tabatsoy
Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.

Everah | Please post in the correct forums. PHP Coding questions should be posted in the PHP - Code forums, not General Discussion.

Everah | Please do not post that your problem is urgent. All problems around here are urgent and the folks that volunteer their time here to help you will get to your problem as soon as they can

Good day,
Please help me in my code. i'm using wamp5. when i'm just refreshing the browser everything is ok but when i close my browser and open it again to see my work everything is gone.

here is my code:

Code: Select all

<?
    $db = mysql_connect("localhost");
    mysql_select_db("examination",$db);     
 
    if (isset($_POST['Submit'])) {
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>dummy</title>
</head>
 
<body>
<?
    echo '<FORM name ="form1" method ="post" action ="dummy.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">'.$selected = $_POST[$question_number_logic];
        if ($selected == $answer) {
            $score++;   
        }
    }'&nbsp;</td>
                </tr>';
        }
    
echo '</table>
<br /> total score is : '.$score.'<br />
 
<Input type = "Submit" Name = "Submit" VALUE = "Select a Radio Button">
</FORM>';
?>
</body>
</html>
please help me with my code thanks.
i badly need this, presentation of prototypes in our school is next week.
please help me


Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:35 am
by Zoxive

Code: Select all

if (isset($_POST['Submit'])) {
Is wrapped around your form.. so yes you would be seeing nothing if you are not posting to that page.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:42 am
by tabatsoy
what should i do then?

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:43 am
by tabatsoy
if i refresh my browser i can still see it.
but when i close my browser and open it again... all is gone except for the submit button

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:48 am
by Zoxive
tabatsoy wrote:if i refresh my browser i can still see it.
but when i close my browser and open it again... all is gone except for the submit button
Exactly. Because when you refresh, the browser is submiting that information again. With $_POST['Submit'] being set.

When you close the browser and open that page $_POST['Submit'] is not set, the if statement is false.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 10:56 am
by tabatsoy
please tell me what should i do.
please :banghead:

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 11:24 am
by RobertGonzalez
Moved to PHP - Code.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 11:25 am
by RobertGonzalez
Almost your entire code is wrapped inside a conditional statement that is checking for a form element named "submit" being sent in the $_POST superglobal array. To keep the form in place move the form code outside of the conditional statement.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 11:31 am
by tabatsoy
Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.

here is my new code:

Code: Select all

<?
    $db = mysql_connect("localhost");
    mysql_select_db("examination",$db);     
 
    if (isset($_POST['Submit'])) {
        echo '<FORM name ="form1" method ="post" action ="dummy.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">'.$selected = $_POST[$question_number_logic];
        if ($selected == $answer) {
            $score++;   
        }
    }'&nbsp;</td>
                </tr>';
        }
    
echo '</table>
<br /> total score is : '.$score.'<br />
 
<Input type = "Submit" Name = "Submit" VALUE = "Select a Radio Button">
</FORM>';
?>
sorry for the sloppy one.
what should i do again?

Everah | Please use the appropriate bbCode tags when posting code in the forms. You can use [code], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight as.

Re: Please help me in my code (urgent)

Posted: Thu Mar 13, 2008 11:47 am
by RobertGonzalez
@tabatsoy, please make sure to wrap any code you post in proper bbCode tags. To find out how to do it, click the edit button on your post above this one and look at how your code is wrapped in [php] tags.

Now what is the problem you are having again?