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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't access HTTP_POST_VARS

Status
Not open for further replies.

cathl

Technical User
Aug 4, 2000
18
0
0
GB
Hi, I am using html templates (with my PHP scripts) which contain forms. In some of the scripts I get nothing when I try and access the form variables when the method is "post". When the method is "get" I can access them no problem. In other scripts with templates on the same site the post variables work fine and as far as I can see there is no difference in the way I am accessing them. Could this be a server problem or could there be something wrong with some of my scripts/templates? By the way I need to use the "post" method not "get" for security/privacy.
Thanks for any help with this.
 
I'd say it's most likely a script problem. If you show an example of your code, both the html form, and the PHP form handler, we'll see what we can do.
 
OK thanks. Here's the form code from the html template:

<form name=&quot;questionnaire&quot; action=&quot;questionnaire.php&quot; method=&quot;get&quot;>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; class=&quot;default&quot; name=&quot;maintable&quot; width=&quot;98%&quot; vspace=&quot;0&quot; hspace=&quot;0&quot;>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;center&quot;><font color=&quot;#990000&quot;>{message}</font></div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;> </td>
</tr>
<tr>
<td colspan=&quot;6&quot;><b>Please supply your name and the full name, address
and telephone number of your company:</b></td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>{nmes} Your Name:
<input type=&quot;text&quot; name=&quot;custname&quot; value=&quot;{FName} {LName}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>{cmes} Company Name:
<input type=&quot;text&quot; name=&quot;compname&quot; value=&quot;{Company}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>{ames} Company Address:
<input type=&quot;text&quot; name=&quot;add1&quot; value=&quot;{add1}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;add2&quot; value=&quot;{add2}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;add3&quot; value=&quot;{add3}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>{pmes} Postcode:
<input type=&quot;text&quot; name=&quot;postcode&quot; value=&quot;{postcode}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>{tmes} Telephone Number:
<input type=&quot;text&quot; name=&quot;telno&quot; value=&quot;{telcode} {telnumber}&quot;>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;6&quot;>
<div align=&quot;right&quot;>
<input type=&quot;submit&quot; name=&quot;send1&quot; value=&quot;Next&quot;>
</div>
</td>
</tr>
</table>
</form>


and here's an example of the PHP code:


if ($send1)
{
if ((!$custname) || (!$compname) || (!$add1) || (!postcode) || (!$telno))
{
$message = &quot;Please enter the details where requested.&quot;;
$Tpl = new Template;
$Tpl -> set_file(&quot;Main&quot;, &quot;questionnaire.ihtml&quot;);
$Tpl -> set_var(array(&quot;FName&quot; => $FName,
&quot;LName&quot; => $LName,
&quot;Company&quot; => $Company,
&quot;telcode&quot; => $telcode,
&quot;telnumber&quot; => $telnumber,
&quot;message&quot; => $message,
&quot;add1&quot; => $add1,
&quot;add2&quot; => $add2,
&quot;add3&quot; => $add3,
&quot;postcode&quot; => $postcode));
// all set send it out..
$Tpl -> parse(&quot;out&quot;, &quot;Main&quot;);
$Tpl -> p(&quot;out&quot;);
}
}

When the method is &quot;get&quot; this code works fine, when the user submits the form &quot;send1&quot; is set and if fields such as custname and compname are not filled in the &quot;if&quot; statement is run. However when the method is &quot;post&quot; in the same situation send1 is not set and the &quot;if&quot; statement is ignored.
Hope this makes sense.
Cath.
 
Use enctype=&quot;multipart/form-data&quot; in your form tag

ie:

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;whatever.php&quot; enctype=&quot;multipart/form-data&quot;>
 
Why the multipart?

He's not using files. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I found that the answer was that there is an issue with IIS not always passing the php session ID correctly and the solution is to include the session ID as a hidden variable in every form with a post method. I tried this and it works.
I only found the answer a couple of months ago, it seems not many people have encountered this problem.
Thanks,
Cath.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top