Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

POST_VARS - having read everything on this site

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

POST_VARS - having read everything on this site

Postby smcpoland » Mon Jun 16, 2003 9:24 am

and in other books (SAMS) WROX etc and php.net

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)

Problem
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
etc

and not

varname == value
varname == value
etc
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
regards
Sean






Code Sample 1
Code: Select all
<html>
<head>
<title>test001</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<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">

</form>
</body>
</html>



Code Sample 2
Code: Select all
<?php
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>";
}
else
{
   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>";

?>
[/code]
smcpoland
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 21, 2003 5:18 am
Location: Colchester, UK

Postby Redcircle » Mon Jun 16, 2003 1:32 pm

$varname = stripslashes($value);

shouldn't that be $value = stripslashes($value)?
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Joan Garnet » Mon Jun 16, 2003 1:58 pm

Try this:
Code: Select all
foreach ($_POST as $key => $value)
{
   $varname = stripslashes($value);
   print "$key == $varname<br>";
}


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


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.