header function problem

Discussion in 'PHP' started by um., Dec 25, 2009.

  1. #1
    i have just created a form to test string function.. i created this func.html


    <form method="post" action="func.php" />
    <p> <textarea name="text" cols="50" rows="5" wrap="virtual"></textarea>
    <br />
    <input type="radio" name="func" value="md5" /> MD5 <br />
    <input type="radio" name="func" value="strlen" /> String Length <br />
    <input type="radio" name="func" value="strrev" /> String Reverse<br />
    <input type ="radio" name="func" value="strtoupper" /> String to Upper<br />
    <input type="radio" name="func" value="strtolower" /> String to lower<br />
    <input type="radio" name="func" value="ucwords" /> First Word to Uper Case<br />
    <input type="submit" name="submit" value="Go" />
    HTML:

    And then created php file "func.php"


    <?
    if (($_POST[text] == "") || $_POST[func] == "")) {
    {
    header("Location: func.html");
    exit;
    }
    
    $result = $_POST[func] ($_POST[text]);
    ?>
    
    <b>The Result is <b><? echo $result ?>
    Code (markup):

    Every thing is working fine when i remove this function

    
    if (($_POST[text] == "") || $_POST[func] == "")) {
    {
    header("Location: func.html");
    exit;
    }
    Code (markup):

    i use this function because if user donot put text or select radio button then header function again bring user to main page..
    Help me out why header function is not working even on other scripts i made.. THANKS
     
    um., Dec 25, 2009 IP
  2. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #2
    Where in the code did you put the function? It should be on the beginning, before the <html> tag. Because I think you can't send another header, if the headers are already set.
     
    shall, Dec 25, 2009 IP
  3. um.

    um. Greenhorn

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #3
    means i have to use like this?

    <?
    if (($_POST[func] == "") && ($_POST[text] == ""))
    	{
        header("Location: func.html"); 
        exit;
    }
    
    $result = $_POST[func] ($_POST[text]);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    
    
    <b>The Result is <b><? echo $result ?>
    
    </body>
    </html>
    
    HTML:
     
    um., Dec 25, 2009 IP
  4. um.

    um. Greenhorn

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Hey SHALL.. You are totally right.. i use it before html tags or delete all html tags and now it is working perfectly.. Thanks to you sir..
     
    um., Dec 25, 2009 IP
  5. shall

    shall Member

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #5
    No problem :)
     
    shall, Dec 25, 2009 IP