By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

POST variables are empty

P: 4
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_type = "workAttachs"; // What is the file type for this section?
$file_path = $datastore_root."/".$owner."/".$attachment_type."/".$thisYear."/".$thisMonth."/".$thisDay;
$link_path = "/".$attachment_type."/".$thisYear."/".$thisMonth."/".$thisDay."/";
function mkPath($path) {
$dirs=array();
$path=preg_replace('/(\/){2,}|(\\\){1,}/','/',$path); //only forward-slash
$dirs=explode("/",$path);
$path="";
foreach ($dirs as $element) {
$path.=$element."/";
if(!is_dir($path)) {if(!mkdir($path)){ return '/tmp';}
}
}
return $path;
}

$upld_dir = mkPath($file_path);
if ((isset($_POST["MMUpload"])) && ($_POST["MMUpload"] == "formUpload")) {
$insertSQL = sprintf("INSERT INTO files (file, content) VALUES (%s, %s)",
GetSQLValueString($_POST['UpldFile'], "text"),
GetSQLValueString($_POST['FKcontent'], "text"));
mysql_select_db($db_common, $common);
$Result1 = mysql_query($insertSQL, $common) or die(mysql_error());
}
if ($_REQUEST['uploadDir']) {
$output_file = array_slice($_FILES['Filedata'], 0, 1);
foreach ($output_file as $files) {
$uploadFile = $upld_dir . $_FILES['Filedata']['name'];
if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile)){
echo '<body onLoad="document.formUpload.submit()">
<form name="form_upload" action='.$_SERVER['PHP_SELF'].'>
<input type="hidden" name="MMUpload" value="formUpload">
<input type="hidden" name="UpldFile" value='.$upld_dir . $files.'>
<input type="hidden" name="LastModBy" value='.$_POST['LastModBy'].'>
<input type="hidden" name="FKcontent" value='.$RecordID.'>
</form>
</body>';
$result = '<body onLoad="document.formUpload.submit()">
<form name="form_upload" action='.$_SERVER['PHP_SELF'].'>
<input type="hidden" name="MMUpload" value="formUpload">
<input type="hidden" name="UpldFile" value='.$upld_dir . $files.'>

<input type="hidden" name="LastModBy" value='.$LastModBy.'>
<input type="hidden" name="FKcontent" value='.$RecordID.'>

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

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// 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('upload_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...
Jan 9 '08 #1
Share this Question
Share on Google+
2 Replies


nathj
Expert 100+
P: 938
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
Jan 23 '08 #2

Atli
Expert 5K+
P: 5,058
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 :)
Jan 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.