POST_VARS - having read everything on this site

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Mon Jun 16, 2003 9:24 am

and in other books (SAMS) WROX etc and

This is sooo annoying ...... what is wrong....

a simple submit form with hidden fields as below at code sample 1, fields are identified with id and name parameters

the resultscript.php code is shown in code sample 2, some simple tracing and a foreach (http_post_vars)

this is the really stupid bit;

when I execute the form (no problems) it goes to the resultspage (no problems) but the

print "$varname == $value" statement prints as follows

value == value
value == value

and not

varname == value
varname == value
as expected

with the result that the rest of the form obviously does not work correctly. The number of results is correct. but not the variables....

Why does the foreach loop not assign the (local) variables the name with its associated value.

This is killing me - time for tea and a kebab I think.............
Thanks in advance

Code Sample 1

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<form action="resultscript.php" method="post">

<input type="hidden" id="transactionstatus" name="transactionstatus" value="1">
<input type="hidden" id="total" name="total" value="2">
<input type="hidden" id="clientid" name="clientid" value="3">
<input type="hidden" id="oid" name="oid" value="4">

<input type="submit" id="button" name="test" value="test">


Code Sample 2

Code: Select all

echo "step point 0\n<br>";

foreach ($HTTP_POST_VARS as $varname => $value)
   $varname = stripslashes($value);
   print "$varname == $value<br>";
if (strcmp(getenv("REQUEST_METHOD"),"post"))
   echo "step point 1\n<br>";
   $msgText = "$oid - Transaction Status - $transactionstatus\n";
   $msgText = $msgText."$oid - Transaction Total  - $total\n";
   $msgText = $msgText."$oid - Transaction Client - $clientid\n";
   $msgText = $msgText."$oid - Transaction OID    - $oid\n";
   mail( "zzz@123", "New booking Result", $msgText, "From: zzz@123" );
   echo "step point 2\n<br>";
   echo "step point 3\n<br>";
   mail( "zzz@123", "New booking Result", "Unsuccessful Post 1", "From: zzz@123" );
   echo "step point 4\n<br>";

   echo "step point 5\n<br>";


User avatar
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Mon Jun 16, 2003 1:32 pm

$varname = stripslashes($value);

shouldn't that be $value = stripslashes($value)?

User avatar
Joan Garnet
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Mon Jun 16, 2003 1:58 pm

Try this:

Code: Select all

foreach ($_POST as $key => $value)
   $varname = stripslashes($value);
   print "$key == $varname<br>";


Post Reply