Solved

PHP post var are "lost"

Posted on 2004-10-06
15
952 Views
Last Modified: 2013-12-12
Hi,

I have been doing PHP dev for quite a while, and have my own scripts for news and various other things, that i know work. However, i have come to use these on a different server, and for some reason, the server seems to be "dropping" the post vars between a form, and the page that processes it.

I have tried doing $HTTP_POST_VARS & $_POST... neither seem to work...

form code:

<FORM ACTION="aframe.php?apage=donews&method=add" METHOD="post" id=frmNewNews name=frmNewNews align="center">
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA><br>&nbsp;<br>
<input type=submit value="Submit news">

processing code:

if(!empty($HTTP_GET_VARS['method']))
{
      $action = $HTTP_GET_VARS['method'];
}

^^ *** This bit works fine *** ^^

if($action=="add")
{
      $headline = $HTTP_POST_VARS['txtHeadline'];
      $story = $HTTP_POST_VARS['txtStory'];

.......etc.......

For some reason, $headline & $story are always just blank if i try to echo (eg echo $story;) them, or do something with them.

Does anyone know why it would be doing this?

Thanks!
0
Comment
Question by:Chrisp455
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 12

Expert Comment

by:minichicken
ID: 12241330
You said you 've tried $_POST, right.... it could be in the PHP.ini setting that
"register_globals" is ON, I think it should be OFF to use $_POST, $HTTP_POST_VARS, $REQUEST.
Maybe try this and see if it works

*************************
$headline = $txtHeadline;
$story = $txtStory;
0
 

Author Comment

by:Chrisp455
ID: 12241569
thanks for the reply, but it doesnt work :( any others ideas?

0
 
LVL 4

Expert Comment

by:Skonen
ID: 12241637
For further debugging purposes, it may be helpful to reveal the contents of the post data array:

print_r($_POST);
0
 

Author Comment

by:Chrisp455
ID: 12241778
doing that, i get

Array ( ) 1
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12241897
which means you are not receiving your post values
may i ask what do you get with print_r ($_GET);

The code looks fine, unless you can use $_GET and $_POST, but i am sure you can do that, I think i did that before, using GET and POST from the same form.
0
 

Expert Comment

by:dj_andyr
ID: 12245899
You are mixing POST and GET which are too different animals, you could just easily define the variables you are passing in the URL as hidden variables (which you can pick up in the post array).

<FORM ACTION="aframe.php" METHOD="post" id=frmNewNews name=frmNewNews align="center">
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA><br>&nbsp;<br>
<input type=hidden name=apage value=donews>
<input type=hidden name=method value=add>
<input type=submit value="Submit news">

0
 

Author Comment

by:Chrisp455
ID: 12246612
Hi,

I use GET and POST for two different things - aframe uses GET to figure out which page it should be including (ie donews), and then donews uses it to figure out what action should be performed. POST is only used for the forms. This method of doing things works fine on my server, just not on this other server =S

This is what i get from print_r($_GET)

Array ( [apage] => donews [method] => add ) 1

Thanks
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 12

Expert Comment

by:minichicken
ID: 12246694
You can also try this:
change your form method to GET so everything is GET and on your processing code page also everything to $HTTP_GET_VARS

<FORM ACTION="aframe.php?apage=donews&method=add" METHOD="GET" id=frmNewNews name=frmNewNews align="center">
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA><br>&nbsp;<br>
<input type=submit value="Submit news">


if(!empty($HTTP_GET_VARS['method']))
{
     $action = $HTTP_GET_VARS['method'];
}

^^ *** This bit works fine *** ^^

if($action=="add")
{
     $headline = $HTTP_GET_VARS['txtHeadline'];
     $story = $HTTP_GET_VARS['txtStory'];

.......etc.......

************************************************************
OR alternatively
I think you should try dj_andyr method for the form part (use hidden values and use POST as the main method)

then you code for processing the method will then be like this:

if(!empty($HTTP_POST_VARS['method']))
{
     $action = $HTTP_POST_VARS['method'];
}

^^ *** This bit works fine *** ^^

if($action=="add")
{
     $headline = $HTTP_POST_VARS['txtHeadline'];
     $story = $HTTP_POST_VARS['txtStory'];

.......etc.......

0
 

Author Comment

by:Chrisp455
ID: 12246904
Changed the form method to get... it sort of works - all the form elements are now being passed to the next page, but now it is dropping the URL vars! (ie the apage=donews&method=add)

I would prefer not to change the way i am passing apage=donews&method=add, but if you feel it is the only way, i will

Thanks
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12246938
If you got GET to work then it should work if you put your URL vars as hidden fields. I know you do not prefer to do it like this but seems like it the way to go, or if you dont want people to see the values in URL then change it to POST and also on the processing page change it to $HTTP_POST_VARS

**********************************************************************
<FORM ACTION="aframe.php" METHOD="GET" id=frmNewNews name=frmNewNews align="center">
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA><br>&nbsp;<br>
<input type=hidden name=apage value="donews">
<input type=hidden name=method value="add">
<input type=submit value="Submit news">

if(!empty($HTTP_GET_VARS['method']))
{
     $action = $HTTP_GET_VARS['method'];
}

^^ *** This bit works fine *** ^^

if($action=="add")
{
     $headline = $HTTP_GET_VARS['txtHeadline'];
     $story = $HTTP_GET_VARS['txtStory'];

.......etc.......

************************************************************
0
 

Expert Comment

by:dj_andyr
ID: 12248781
I just tested your code :

HTML FORM ---------------------------------/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<FORM ACTION="aframe.php?apage=donews&method=add" METHOD="POST" id=frmNewNews name=frmNewNews align="center">
Headline<br>
<input type=textbox name=txtHeadline>
<br>
Story<br>
<TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA>
<br>
&nbsp;<br>
<input type=submit value="Submit news">
</body>
</html>

AFRAME.PHP  ---------------------------------/

<?

if(!empty($HTTP_GET_VARS['method']))
{
     $action = $HTTP_GET_VARS['method'];
}

if($action=="add")
{
 print_r($HTTP_POST_VARS);
}

?>

OUTPUT ---------------------------------/

Array ( [txtHeadline] => THIS IS SET [txtStory] => TEST POST ARRAY )

The problem must lie in your PHP setup, to allow us to debug it would be best giving us access to the PHP info page.

<?

phpinfo();

?>



0
 

Author Comment

by:Chrisp455
ID: 12250721
Hi,

i have a PHP info page here

http://www.cw-meltingpoint.com/phpinfo.php

I have looked through it before, as the host said they are willing to change something if i found a problem, but i cant see what would be causing it :(

Thanks!
0
 
LVL 12

Accepted Solution

by:
minichicken earned 250 total points
ID: 12250934
I am just guessing here.....

I see that the register_globals in your PHP is "On", well in PHP 4 it off by default

Try use this at the top of your page

ini_set("register_globals", "0"); //turn register global off

Purely guessing.... worth a try though.
0
 

Author Comment

by:Chrisp455
ID: 12251135
It worked!!

I didnt realise you could turn off register globals just like that!!!

Thank you very much!
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12251321
No Prob :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now