SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Header() causes an error

    Hello all,
    I know that this is a basic question.
    but I have to submit in very urgent .It working fine except this warning
    Header cannot modify.
    After intregation with sdk
    My cose is
    PHP Code:
    <?php
    // Load and Start IPB SDK
    require_once "../ipbsdk/ipbsdk_class.inc.php";
    $SDK =& new IPBSDK();
    //abc
    // We're logged in. Retrieve member info
        
    $info $SDK->get_info();

        
    // Generate Bar Content
        
    $member_name $info['name'];
        
    $member_id $info['id'];
    // =====================
    // START MEMBER ONLY
    // =====================

    if ($SDK->is_loggedin()) {
          
    // Code for logged in users goes here
          
    echo 'You are logged in!!!<br />';
          
          
    /*
    The connection with database
    */
    include('dbcon.php');

    /*
    Checking all the answer user has given or not
    */
    if(isset($_POST['B1'])) {
        if((isset(
    $_POST['1']))==false) {
            exit (
    "1.Answer Missing.");
        }
        if((isset(
    $_POST['2']))==false) {
            exit (
    "2.Answer Missing.");
        }
        if((isset(
    $_POST['3']))==false) {
            exit (
    "3.Answer Missing.");
        }
        if((isset(
    $_POST['4']))==false) {
            exit (
    "4.Answer Missing.");
        }
        if((isset(
    $_POST['5']))==false) {
            exit (
    "5.Answer Missing.");
        }
        if((isset(
    $_POST['6']))==false) {
            exit (
    "6.Answer Missing.");
        }
        if((isset(
    $_POST['7']))==false) {
            exit (
    "7.Answer Missing.");
        }
        if((isset(
    $_POST['8']))==false) {
            exit (
    "8.Answer Missing.");
        }
        if((isset(
    $_POST['9']))==false) {
            exit (
    "9.Answer Missing.");
        }
        if((isset(
    $_POST['10']))==false) {
            exit (
    "10.Answer Missing.");
        }
        
    /*
        Storind all the values from user
        */
        
    $sub=empty($_POST['B1'])?'':$_POST['B1'];
        
    $user=empty($_POST['user'])?'':$_POST['user'];
        
    $uid=empty($_POST['uid'])?'':$_POST['uid'];
        
    $a=empty($_POST['1'])?'':$_POST['1'];
        
    $b=empty($_POST['2'])?'':$_POST['2'];
        
    $c=empty($_POST['3'])?'':$_POST['3'];
        
    $d=empty($_POST['4'])?'':$_POST['4'];
        
    $e=empty($_POST['5'])?'':$_POST['5'];
        
    $f=empty($_POST['6'])?'':$_POST['6'];
        
    $g=empty($_POST['7'])?'':$_POST['7'];
        
    $h=empty($_POST['8'])?'':$_POST['8'];
        
    $i=empty($_POST['9'])?'':$_POST['9'];
        
    $j=empty($_POST['10'])?'':$_POST['10'];

        
    $qnum1=empty($_POST['qnum1'])?'':$_POST['qnum1'];
        
    $qnum2=empty($_POST['qnum2'])?'':$_POST['qnum2'];
        
    $qnum3=empty($_POST['qnum3'])?'':$_POST['qnum3'];
        
    $qnum4=empty($_POST['qnum4'])?'':$_POST['qnum4'];
        
    $qnum5=empty($_POST['qnum5'])?'':$_POST['qnum5'];
        
    $qnum6=empty($_POST['qnum6'])?'':$_POST['qnum6'];
        
    $qnum7=empty($_POST['qnum7'])?'':$_POST['qnum7'];
        
    $qnum8=empty($_POST['qnum8'])?'':$_POST['qnum8'];
        
    $qnum9=empty($_POST['qnum9'])?'':$_POST['qnum9'];
        
    $qnum10=empty($_POST['qnum10'])?'':$_POST['qnum10'];
        

        if(
    $sub=="Click") {
            
    $da=date('Y-m-d');

            
    $sq="select * from `user_result` where username='$user' and udate='$da'";
            
    $result=mysql_query($sq) or
                die(
    __LINE__.mysql_error());
            
    $row_result=mysql_num_rows($result);
                        if(
    $row_result>0)
                     {  
                            
                            
    header("Location: /quiz/fail.php?user=$user");
                     }
                     else 
                    {

    $ins="INSERT INTO `user_result` ( `uid` , `username` , `qid1` , `ans1` , `qid2` , `ans2` , `qid3` , `ans3` , `qid4` , `ans4` , `qid5` , `ans5` , `qid6` , `ans6` , `qid7` , `ans7` , `qid8` , `ans8` , `qid9` , `ans9` , `qid10` , `ans10`,`udate` ) 
    VALUES (
    '
    $uid', '$user', '$qnum1', '$a', '$qnum2', '$b', '$qnum3', '$c', '$qnum4', '$d', '$qnum5', '$e', '$qnum6', '$f', '$qnum7', '$g', '$qnum8', '$h', '$qnum9', '$i', '$qnum10', '$j',CURDATE())";
    echo 
    "$ins";
    mysql_query($ins) or
        die(
    "The Data has not been inserted.");
    header("Location: /quiz/suc.php?user=$user");
                      }
                             }
    }
    ?>

    <FORM METHOD=POST ACTION="<? echo $_SERVER['PHP_SELF'?>">
    <p>User Name<INPUT TYPE="text" NAME="user" value="<? echo $member_name ?>"></p>
    <p>uid<INPUT TYPE="text" NAME="uid" value="<? echo $member_id ?>"></p>
    <?

    $tmp 
    range(111); 
    shuffle($tmp); 
    $number=array(1,2,3,4,5,6,7,8,9,10); 
    $j=0
    for(
    $i=1;$i<=10;$i++) { 
        
    $curi $tmp[$i]; 
    $si="select * from questionare where qid=$curi"

    //$si="select * from questionare where qid=$tmp['$i']"; 

    $resulti=mysql_query($si) or 
    die(
    "The $resulti fetching has some problem".mysql_error()); 
    while(
    $rsi=mysql_fetch_array($resulti)) { 
          
        
    ?> 
    <p><? echo $number[$j].". ".$rsi['question']; ?></p>
    <p><INPUT TYPE="hidden" NAME="qnum<? echo $number[$j?>" value="<? echo $curi?>"></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>" value="<? echo $rsi['c1']; ?>"><? echo $rsi['c1']; ?></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>"value="<? echo $rsi['c2']; ?>"><? echo $rsi['c2']; ?></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>"value="<? echo $rsi['c3']; ?>"><? echo $rsi['c3']; ?></p>
    <?
        
    }
    $j=$j+1;
    }    
    ?>
            <INPUT TYPE="submit" name="B1" Value="Click">
    </FORM>
          
    <?      
          
    }
    else {
          
    // Code for guests goes here
          
    echo 'You are not logged in!';
    }

    // =====================
    // END MEMBER ONLY
    // =====================
    It causes for header function but i have to use it.
    Is there any solution ?
    -::Ujjwal::-
    Visit My Site

  2. #2
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Silver Spring, MD
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have the "echo 'You are logged in!!!<br />'; " line at the beginning. After sending content out to the browser like that you're not going to be allowed to send a header. There may be others, I didn't check the code that carefully. If removing that echo line makes it work, then you need to find a way to show that message after any possible header() calls.
    www.ratethatcommentary.com:
    DVD commentary track ratings/reviews.

  3. #3
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah u r right
    there is 2 echo.
    anyway I have to remove it but.
    I want to pull all the questions from questionare and then that value passed into the
    $tmp = range(0, $row_result);
    for making the max limit dynamic.
    But in this case It shows not 10 values all the time.
    sometimes in this order 1,2,5,6,9,10
    What is the reason????
    I want to show only 10 questions to user(1 to 10) and that is coming random order from all the data in our databse questionare table.
    My code is
    PHP Code:
    $se="select * from questionare";
    $r1=mysql_query($se) or
    die("hnhk");
    $row_result=mysql_num_rows($r1);
                        
    $tmp = range(0, $row_result); 
    shuffle($tmp); 
    $number=array(1,2,3,4,5,6,7,8,9,10); 
    $j=0; 
    for($i=1;$i<=10;$i++) { 
        $curi = $tmp[$i]; 
    $si="select * from questionare where qid=$curi"; 

    //$si="select * from questionare where qid=$tmp['$i']"; 

    $resulti=mysql_query($si) or 
    die("The $resulti fetching has some problem".mysql_error()); 
    while($rsi=mysql_fetch_array($resulti)) { 
          
        ?> 
    <p><? echo $number[$j].". ".$rsi['question']; ?></p>
    <p><INPUT TYPE="hidden" NAME="qnum<? echo $number[$j?>" value="<? echo $curi?>"></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>" value="<? echo $rsi['c1']; ?>"><? echo $rsi['c1']; ?></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>"value="<? echo $rsi['c2']; ?>"><? echo $rsi['c2']; ?></p>
    <p><INPUT TYPE="radio" NAME="<? echo $number[$j?>"value="<? echo $rsi['c3']; ?>"><? echo $rsi['c3']; ?></p>
    <?
        
    }
    $j=$j+1;
    }    
    ?>
            <INPUT TYPE="submit" name="B1" Value="Click">
    </FORM>
    Can you guide me
    -::Ujjwal::-
    Visit My Site

  4. #4
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ujwal,

    try by putting ob_start() at the top of the page below <?php .

    Arunkumar
    Where there is a will there is a way
    ArunKumar

  5. #5
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys , thankx for replying.
    Code:

    $tmp = range(0, $row_result);

    In this case 9 values are being stored in this $tmp array . But it should always store 10 unique values(max value will be highest of the questioanre table) . How to ensure that ?
    -::Ujjwal::-
    Visit My Site

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Morning Ujjwal,
    Have you considered letting mysql do the selection?
    PHP Code:
    $questions mysql_query("select * from questionare ORDER BY RAND() LIMIT 10"); 
    Try it.....!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No no ,I have solved it.The problem is that databse some value aredelete and if some fetching value are same with that value and then that's why some data are not coming.
    Thanks all I have solved it
    -::Ujjwal::-
    Visit My Site


Bookmarks

Posting Permissions

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