Jump to content

Recommended Posts

Hello,

I have the following code:

 

 

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') ;

}

?>

 

 

 

My problem is that the two top POST variables (in red bold) values are not posting in the output form section (in bold blue) and I do not know why, the POST variable values are echoing fine so I know they are being posted from the previous page...Thanx for any help...

 

Link to comment
https://forums.phpfreaks.com/topic/85249-post-variables-are-emptynot-sure-why/
Share on other sites

You posted

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

Was the problem

 

However, your code is

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

 

More importantly

<form name="form_upload" action='.$_SERVER['PHP_SELF'].'>

you're missing method="post"

You posted

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

Was the problem

 

However, your code is

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

 

More importantly

<form name="form_upload" action='.$_SERVER['PHP_SELF'].'>

you're missing method="post"

 

Thanks for the help, but I don't see what is wrong here?

 

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

The names of the two fields you have used are LastModBy and FKcontent. These will be the names of the keys in the $_POST array, and so need to be the names used to access these variables. You should have:

 

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

 

The names of the two fields you have used are LastModBy and FKcontent. These will be the names of the keys in the $_POST array, and so need to be the names used to access these variables. You should have:

 

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

 

 

But these post variables

 

$RecordID = $_POST['PKid'];

$LastModBy= $_POST['LastModBy'];

 

contain values that were posted from the previous page...what I am doing (or want to be doing) is assigning those post variable values($_POST['PKid']) to a new variable($RecordID) and then I want to read that new variable($RecordID) value from this form (in blue):

 

($_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" method="post" 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>';

 

$result = '<body onLoad="document.formUpload.submit()">

<form name="form_upload" method="post"  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>';

}

 

I hope that makes sense,

Thanx...

 

$_POST['PKid'] doesn't exist because there is no input named PKid

 

can't $_POST['PKid'] hold a value submitted through a form and hidden field from a previous page such as:

 

<form method="post" name="form_upload" action="/page.php">

<input type="hidden" name="PKid" value="<?php echo $rowRSViewContent['PKid']; ?>" />

<input type="hidden" name="MMUpload" value="form_upload" />

</form>

 

 

sorry im lost. you should be fine if that has a value, can you tell us whats the problem now?

 

Ok...so I have view.php page which has the following code:

 

<form method="post" name="form_upload" action="uploadscript.php">

  <input type="hidden" name="PKid" value="<?php echo $rowRSViewContent['PKid']; ?>" />

  <input type="hidden" name="LastModBy" value="<?php echo $rowRSViewContent['LastModBy']; ?>" />

  <input type="hidden" name="MMUpload" value="form_upload" />

</form>

 

and the uploadscript.php page with the following code:

 

//BEGIN 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') ;

}

?>

 

//END PHP

 

Upon clicking the edit button on the view.php page I get taken to the uploadscript.php page. Now, I know the hidden field values from view.php are getting passed to the uploadscript.php page because when I echo these:

      $RecordID = $_POST['PKid'];

      $LastModBy= $_POST['LastModBy'];

 

they show fine, the problem is that they are not showing in this form's fields (in blue bold):

 

//BEGIN PHP

 

 

// 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') ;

}

?>

 

//END PHP

 

Can this somehow be a variable scope issue?

 

Thanx

that is a hidden field so its hidden you can only see them on your src code but not on the browser.. replacehidden with text to be displayed on your browser  is that what you mean?

 

No they should be displayed when I do a test by outputting the form to a txt file...

 

<body onLoad="document.form_upload.submit()">

<form name="form_upload" method="post" action="uploadscript.php">

<input type="hidden" name="MMUpload" value="form_upload">

<input type="hidden" name="UpldFile" value="/file.pdf">

<input type="hidden" name="FKContent" value="">

<input type="hidden" name="LastModBy" value="">

</form>

</body>

 

You see how the hidden fields in bold blue output empty values....

<?
$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>';
echo 'test  teng'.$LastModBy.'>>>>>>>>>>>>'.$RecordID;
$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') ;
}
?>

 

try and tell me what happen

<?
$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>';
echo 'test  teng'.$LastModBy.'>>>>>>>>>>>>'.$RecordID;
$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') ;
}
?>

 

try and tell me what happen

 

Nothing shows up...

At first glance I noticed method="POST" is missing from your form element

 

Find:

<form name="form_upload" action='.$_SERVER['PHP_SELF'].'>

 

Replace

<form name="form_upload" action='.$_SERVER['PHP_SELF'].' method="POST">

 

 

Thanks...thats already taken care of...i just forgot to put it there...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.