Please help me in my code (urgent)

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

Please help me in my code (urgent)

Post 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.
Last edited by RobertGonzalez on Thu Mar 13, 2008 11:23 am, edited 1 time in total.
Reason: Added tags note, correct forum note, urgency note
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Please help me in my code (urgent)

Post 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.
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

Re: Please help me in my code (urgent)

Post by tabatsoy »

what should i do then?
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

Re: Please help me in my code (urgent)

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Please help me in my code (urgent)

Post 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.
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

Re: Please help me in my code (urgent)

Post by tabatsoy »

please tell me what should i do.
please :banghead:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help me in my code (urgent)

Post by RobertGonzalez »

Moved to PHP - Code.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help me in my code (urgent)

Post 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.
tabatsoy
Forum Commoner
Posts: 29
Joined: Thu Mar 13, 2008 10:14 am

Re: Please help me in my code (urgent)

Post 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.
Last edited by RobertGonzalez on Thu Mar 13, 2008 11:45 am, edited 1 time in total.
Reason: bbCode tags note
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Please help me in my code (urgent)

Post 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?
Post Reply