Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 961
  • Last Modified:

PHP post var are "lost"

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
Chrisp455
Asked:
Chrisp455
  • 6
  • 6
  • 2
  • +1
1 Solution
 
minichickenCommented:
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
 
Chrisp455Author Commented:
thanks for the reply, but it doesnt work :( any others ideas?

0
 
SkonenCommented:
For further debugging purposes, it may be helpful to reveal the contents of the post data array:

print_r($_POST);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Chrisp455Author Commented:
doing that, i get

Array ( ) 1
0
 
minichickenCommented:
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
 
dj_andyrCommented:
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
 
Chrisp455Author Commented:
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
 
minichickenCommented:
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
 
Chrisp455Author Commented:
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
 
minichickenCommented:
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
 
dj_andyrCommented:
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
 
Chrisp455Author Commented:
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
 
minichickenCommented:
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
 
Chrisp455Author Commented:
It worked!!

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

Thank you very much!
0
 
minichickenCommented:
No Prob :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now