Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multipart/form-data and variable problem

Status
Not open for further replies.

gbrian

IS-IT--Management
Sep 22, 2004
96
0
0
US
I'm having a strange problem--when I use this enctype on my form (for a file upload), I encounter a strange problem with other form variables that are passed back to the script.

IE--
<input class="a" type="submit" name="action" value="Make Changes">

If I print the value of $action, I do in fact see Make Changes, however-- the statement else if ($action == "Make Changes") { } does not work. I also added to the very top of my .php script if($action=="Make Changes"){echo "test";} -- it doesn't see it.

Am I missing something?
 
Try using $_POST['action'] in your comparisons. Also, you might want to dump out the whole $_POST superglobal array:
Code:
echo '<pre>';print_r($_POST);echo '</pre>';
to see what is being POSTed to your script.

Ken
 
Nothing is being posted...why would this happen?
 
Your form may be using get to send the form data across pages -- inspect the form tag on the previous page. If method="" is omitted or is saying method="get" than you will need to inspect $_GET superglobal rather than $_POST. Simply replace them in the print_r statement.
 
<form enctype="multipart/form-data" method="post" action="news.php">

If I replace news.php with asdf.php it will still come back to the same page--with no posted variables. Could the action not be pointing correctly?
 
I don't understand. Everything posts correctly when I am not using multipart/form-data as the enctype.

 
Update--it must be posted: If I echo $action it gives me a value, print_r($_POST) shows nothing, however.

And even though $action outputs "Make Changes", $action=="Make Changes" returns false...it must be something to do with the encoding type...

anyone have any insight?
 
Could be you're using an old version of php. $_POST was introduced in 4.1.0 as a replacement for $HTTP_POST_VARS. You could try using that.
 
That was it, thanks. Now I'm back at my original problem though:

[action] => Make Changes

However, $action == "Make Changes" returns false. If I get rid of the multipart/form-data encoding, it returns true?

 
Your problem might be the "make changes", as the " " will most likely be replaced with %20 or + (URL Encoded)

Try changing it to:
<input... value="update"

OR:

Try this for a change:
Code:
<form enctype="multipart/form-data" method="post" action="news.php?action=update">


Olav Alexander Mjelde
Admin & Webmaster
 
Try
$action = trim($HTTP_POST_VARS['action]);
if ($action == 'Make Changes') {
echo 'true';
} else {
echo 'false';
}

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top