Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_POST not working.it aint producing any values

    PHP Code:
    <?php
        $query 
    "Select * from users where username = '$user' ";
        
    $result mysql_query($query) or die(mysql_error());
        
    $row mysql_fetch_array($result);

        
    $test $_POST['test1'];
        
    $ques "Select * from questions where testname = '$test' ";
        
    $qres mysql_query($ques) or die(mysql_error());
        
    $qdetails mysql_fetch_array($qres);
        
    $id $qdetails['id'];
        
    $testname $qdetails['testname'];
        
    $ans "Select * from answers where qid = $id";
        
    $ares mysql_query($ans) or die(mysql_error());
        if(
    $qdetails) {
        
    ?>
        <div class="padding">

        <form name="answerform" action="answer.php" method="POST">
        <h3>&nbsp;</h3>
        <input name="test2" id="test2"  type="text" value="<?php echo $qdetails['testname'];?>"      /><h3><?php echo $qdetails['text'];?></h3>
         <input name="test3" id="test3"  type="text" value="<?php echo      $qdetails['testseries'];?>" /><h3><?php echo $qdetails['text'];?></h3>
        <br />
        <br />
        <br />
        <?php while($opdetails mysql_fetch_assoc($ares)) { ?>
        <input class="text" id="opt2" name="correctans" type="radio" value="<?php echo $opdetails['text']; ?>" /><br /><?php echo $opdetails['text']; ?>  <?php }?>
        <div class="two-fields clearfix".
        <p class="confirm">&nbsp;</p>
        </div>
        <input type="submit" value="SUBMIT ANSWER" />
        </form>
        </div>
        </div>
        </div>
     <?php }
    this is the code for the program where i am creating the fields i want to fetch the data from the input fields with the name test 2 and test 3 in answer.php

    PHP Code:
        $query "Select score from users where username = '$user' ";
        
    $result mysql_query($query) or die(mysql_error());
        
    $row mysql_fetch_array($result);
        
    $user_score $row['score'];

        
    print_r($_REQUEST);
        
    $tester $_POST['test3'];
        
    $test $_POST['test2'];
        
    print_r($_POST);
        
    var_dump($_POST);
        
    $ques "Select * from questions where testname = '$test' And testseries = '$tester' ";
        
    $result mysql_query($ques) or die(mysql_error());
        
    $row mysql_fetch_array($result);
        
    $qid $row['id'];
        
    $score $row['score'];
        if(isset(
    $_POST['correctans']))
        {
        
    $answer $_POST['correctans'];
        }
        else
        {
        
    $answer '';
        }
        
    $fetch_ans "Select * from answers where correct = 1 AND qid = $qid";
        
    $result mysql_query($fetch_ans) or die(mysql_error());
        
    $row mysql_fetch_array($result);
        
    $id $row['id'];
        
    $correctans $row['text'];

        if(
    '$correctans' == '$answer')
        {
        
    $user_score += $score;
        
    $qid++;
        
    $query "Update users set score = $user_score  where username = '$user'";
        
    $res mysql_query($query) or die(mysql_error());
        if(
    $res) {
          
        
    header("Location: answer.php");  
        }
        }else
        { 
        
    header("Location: answer.php"); 
        }


        
    ?> 
    THIS IS answer.php and here i try to post information from test2 and test3 fields but i am not getting any output
    the output shows blank array()
    and unidentified index test2
    and unidentified index test3
    i am not able to figure out the error
    any help will be highly appreciated
    and forgive me if i have made any mistakes in posting the question since i am a newbie at CODINGFORUMS
    Last edited by rags_asr; 01-12-2012 at 01:49 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,354
    Thanks
    61
    Thanked 529 Times in 516 Posts
    What did your print_r($_REQUEST) show?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    What did your print_r($_REQUEST) show?
    it shows an empty array
    the form content that i want is not getting posted for some reason which i am not able to figure out.
    i really appreciate your help

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,354
    Thanks
    61
    Thanked 529 Times in 516 Posts
    You might want to try setting the form to multipart data then as iirc that sometimes blocks post data being sent if you are also submitting files.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •