POST variables are empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daav31
    New Member
    • Dec 2007
    • 4

    #1

    POST variables are empty

    Hello,
    I have the following code:

    [PHP]

    $RecordID = $_POST['PKid'];
    $LastModBy= $_POST['LastModBy'];

    // These datetime vars live in globals.php
    $mySQLToday = $thisYear.'-'.$thisMonth.'-'.$thisDay; // prints todays date in YYYY-MM-DD format
    $attachment_typ e = "workAttach s"; // What is the file type for this section?
    $file_path = $datastore_root ."/".$owner."/".$attachment_t ype."/".$thisYear ."/".$thisMont h."/".$thisDay;
    $link_path = "/".$attachment_t ype."/".$thisYear ."/".$thisMont h."/".$thisDay. "/";
    function mkPath($path) {
    $dirs=array();
    $path=preg_repl ace('/(\/){2,}|(\\\){1,}/','/',$path); //only forward-slash
    $dirs=explode("/",$path);
    $path="";
    foreach ($dirs as $element) {
    $path.=$element ."/";
    if(!is_dir($pat h)) {if(!mkdir($pat h)){ return '/tmp';}
    }
    }
    return $path;
    }

    $upld_dir = mkPath($file_pa th);
    if ((isset($_POST["MMUpload"])) && ($_POST["MMUpload"] == "formUpload ")) {
    $insertSQL = sprintf("INSERT INTO files (file, content) VALUES (%s, %s)",
    GetSQLValueStri ng($_POST['UpldFile'], "text"),
    GetSQLValueStri ng($_POST['FKcontent'], "text"));
    mysql_select_db ($db_common, $common);
    $Result1 = mysql_query($in sertSQL, $common) or die(mysql_error ());
    }
    if ($_REQUEST['uploadDir']) {
    $output_file = array_slice($_F ILES['Filedata'], 0, 1);
    foreach ($output_file as $files) {
    $uploadFile = $upld_dir . $_FILES['Filedata']['name'];
    if(move_uploade d_file($_FILES['Filedata']['tmp_name'], $uploadFile)){
    echo '<body onLoad="documen t.formUpload.su bmit()">
    <form name="form_uplo ad" action='.$_SERV ER['PHP_SELF'].'>
    <input type="hidden" name="MMUpload" value="formUplo ad">
    <input type="hidden" name="UpldFile" value='.$upld_d ir . $files.'>
    <input type="hidden" name="LastModBy " value='.$_POST['LastModBy'].'>
    <input type="hidden" name="FKcontent " value='.$Record ID.'>
    </form>
    </body>';
    $result = '<body onLoad="documen t.formUpload.su bmit()">
    <form name="form_uplo ad" action='.$_SERV ER['PHP_SELF'].'>
    <input type="hidden" name="MMUpload" value="formUplo ad">
    <input type="hidden" name="UpldFile" value='.$upld_d ir . $files.'>

    <input type="hidden" name="LastModBy " value='.$LastMo dBy.'>
    <input type="hidden" name="FKcontent " value='.$Record ID.'>

    </form>
    </body>';
    }
    $filename = 'test.txt';

    // Let's make sure the file exists and is writable first.
    if (is_writable($f ilename)) {
    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename , 'a')) {
    echo "Cannot open file ($filename)";
    exit;
    }
    // Write $somecontent to our opened file.
    if (fwrite($handle , $result) === FALSE) {
    echo "Cannot write to file ($filename)";
    exit;
    }
    echo "Success, wrote ($result) to file ($filename)";
    fclose($handle) ;
    } else {
    echo "The file $filename is not writable";
    }
    }
    }
    if ($_REQUEST['action'] == 'getMaxFilesize ') {
    echo "&maxFilesize=" .ini_get('uploa d_max_filesize' ) ;
    }
    ?>[/PHP]


    My problem is that the two top POST variable values are not posting in the output form section (in bold and italics), though the POST variable values are echoing fine so I know they are being posted from the previous page...Thanx for any help...
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Hi,

    It seems that the form is submitting to itself, at least thats how it looks to me. If this is correct then when the page loads initially there is nothing set but then when the form is submitted something is set. Is that correct?

    If I've got it so far it would seem that you need to add a method="post" to the main form tag.

    Also the onload call references the submit of a form that I cannot see defined - but this could be in another file or I could have just missed it.

    I would check you have all the correct methods in place and the correct form and variable names - I know this seems obvious but sometimes that's all it is. I know I've been caught like that before now.

    Finally, is the logic correct? It seems that the form is submitting to the same page then when it gets there with the information it is submitting to itself again, and then again and so on. Perhpas I've missed something but it seemed potentially infinite to me.

    I hope that was a help and not just a waste of time due to my lack of comprehension.

    Cheers
    nathj

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      I think nathj is correct.

      The form has no method parameter, and I would assume browsers used the GET protocol as the default method, which would result in an empty $_POST super-global.

      Btw. Your code would be so much more readable if you indented functions and loops. And comments also help sometimes :)

      Comment

      Working...