Aggrevated! Why are my POST variables not passing?

Discussion in 'PHP' started by Rockstr27, Jan 25, 2010.

  1. #1
    This script seemed to work before and not it is not - I narrowed the issue down to my variables not even passing - here is the code - can anyone help me by seeing by they may not be passing?

    <form action="profile.php" method="POST"><input type="hidden" name="profile" value="user"/><input type="image" src="image.jpg" width=114 height=79></form>
    Code (markup):
    ... and then in the profile.php script:

    $proname=$_REQUEST["profile"];
    echo "proname: ".$proname;
    Code (markup):
    ... and I get nothing, and I also tried:

    $proname=$_POST["profile"];
    echo "proname: ".$proname;
    Code (markup):
    ... and both echos:

    proname: 
    Code (markup):
    Can anyone see what could be wrong? All my other pages that use POST variables are working fine - just this particular one ... help appreciated - thanks!
     
    Rockstr27, Jan 25, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    should work, are you sure your echoing $proname on the same page where the form is?
     
    danx10, Jan 25, 2010 IP
  3. Rockstr27

    Rockstr27 Well-Known Member

    Messages:
    1,052
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    115
    #3
    I am echoing $proname on profile.php which is the file referenced in the action on the form ... I'm stripping all the other code off the page to see if I can narrow down the conflict ... makes no sense to me ...
     
    Rockstr27, Jan 25, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Are you sure you haven't overwritten the $proname variable?

    Also try adding error_reporting(E_ALL); at the top of profile.php... see if that brings any errors.
     
    danx10, Jan 25, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    At the very top of your code, put:

    echo "<pre>"; var_dump($_POST); echo "</pre>";
    PHP:
    That will tell you what's really coming in to $_POST.
     
    SmallPotatoes, Jan 25, 2010 IP
  6. Rockstr27

    Rockstr27 Well-Known Member

    Messages:
    1,052
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    115
    #6
    I am now posting to profile2.php which is just an echo statement along with the following:

    <HTML>
    <HEAD>
    
    <?php 
    
    error_reporting(E_ALL);
    
    echo "<pre>"; var_dump($_POST); echo "</pre>";
    
    if ($_REQUEST) {
    foreach (array_keys($_REQUEST) as $key) {
    $$key = $_REQUEST[$key];
    echo $key.': '.$$key.'<br />';
    }
    }
    
    ?>
    </BODY>
    </HTML>
    PHP:
    ... and this is the output ...

    array(0) {
    }
    
    __utma: 149885684.114437545.1259699287.1264189676.1264217867.19
    __utmz: 149885684.1264189676.18.6.utmcsr=webmessenger.yahoo.com|utmccn=(referral)|utmcmd=referral|utmcct=/
    PHPSESSID: 0547e08ee48fb66012dc149002a8ac3c
    PHP:
    I guess now I am going to strip the file with the form on it to have that be the only thing on the page and see what happens there ...

    UPDATE: Well, a stripped down form submits the variables as expected to the page ... so apparently I have a conflict somewhere in my code that I have to track down ...
     
    Last edited: Jan 25, 2010
    Rockstr27, Jan 25, 2010 IP
  7. Rockstr27

    Rockstr27 Well-Known Member

    Messages:
    1,052
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    115
    #7
    Ok - I figured out that when I post to a URL with the whole URL with an absolute path, it does not pass the variables, but when I pass it with just the file name referenced, ie. <form action="profile.php" method="POST"> instead of <form action="http://www.domain.com/profile.php" method="POST">, then it works ...

    I need to code the URLs in because I am using mod re-write on here and it will result in file not found errors if I do not code the URL that way, but why is the post not working? That still does not make sense to me - and it works on my other pages?
     
    Rockstr27, Jan 25, 2010 IP
  8. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you are using mod_rewrite to create redirects, you will lose POST variables in the process.
     
    SmallPotatoes, Jan 25, 2010 IP