473,473 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

POST variables are empty

4 New Member
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
2 2206
nathj
938 Recognized Expert Contributor
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
5,058 Recognized Expert Expert
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

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

Similar topics

2
by: Dariusz | last post by:
I have a small form that on button press submits to a PHP file for further processing into a database. I have to change the script as it allows blank / nothing to be submitted to the database. ...
2
by: mikespam | last post by:
Hello, I'm using nusphere phped to develop php files. I have written to files named a.php and b.php. a.php: ------ <html> <body> please enter two numbers in the form.<br> <form action =...
3
by: Bernd Kohler | last post by:
Hello, I got an annoying problem using the POST-method to send a form's data: I put a login-form on the page which is sent by the POST-method to itself. After that the content of the...
0
by: Lucas Branca | last post by:
python 2.1.3 Debian woody Apache 1.3.26 mod python 2.7.8 ## ---- formtest.html ---- ## <form action="/formtest.py/main" method="POST"> <input type="submit" value="go" name="action"> <input...
2
by: Asp Help | last post by:
I'm working on a ASP applicatition to create Windows 2000 users. Because I don't want everybody to have access to the site I've changed te security in IIS 5.0 which runs on a windows 2000 Sp4...
2
by: CCP | last post by:
I've got a simple HTML page containing a form and a few hidden variables. This form post into a .Net application (that lives in a seperate directory). The first thing I do in my codebehind is...
24
by: moriman | last post by:
Hi, The script below *used* to work. I have only just set up a server, PHP etc again on my Win98 system and now it doesn't? On first loading this page, you would have $p = and the button...
1
by: Muchach | last post by:
Hello, Ok so what I've got going on is a form that is populated by pulling info from database then using php do{} to create elements in form. I have a text box in each table row for the user to...
3
by: radix | last post by:
Hello, I have a aspx page with ajax scriptmanger update panel etc. I also have public string variables on the aspx page. Whenever postback happens from Ajax update panel, at server side all...
6
by: cethie | last post by:
In the code below, DoGet is working very stable. But DoPost throws an uncatcheable InvalidOperationException randomly. I am lost. Any pointers will be of immense help. /* Environment...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.