Chrisp455
asked on
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=d onews&meth od=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>  ;<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['txtHeadli ne'];
$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!
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=d
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA
<input type=submit value="Submit news">
processing code:
if(!empty($HTTP_GET_VARS['
{
$action = $HTTP_GET_VARS['method'];
}
^^ *** This bit works fine *** ^^
if($action=="add")
{
$headline = $HTTP_POST_VARS['txtHeadli
$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!
ASKER
thanks for the reply, but it doesnt work :( any others ideas?
For further debugging purposes, it may be helpful to reveal the contents of the post data array:
print_r($_POST);
print_r($_POST);
ASKER
doing that, i get
Array ( ) 1
Array ( ) 1
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.
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.
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>  ;<br>
<input type=hidden name=apage value=donews>
<input type=hidden name=method value=add>
<input type=submit value="Submit news">
<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
<input type=hidden name=apage value=donews>
<input type=hidden name=method value=add>
<input type=submit value="Submit news">
ASKER
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
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
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=d onews&meth od=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>  ;<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['txtHeadlin e'];
$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['txtHeadli ne'];
$story = $HTTP_POST_VARS['txtStory' ];
.......etc.......
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=d
Headline<br> <input type=textbox name=txtHeadline><br>
Story<br> <TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA
<input type=submit value="Submit news">
if(!empty($HTTP_GET_VARS['
{
$action = $HTTP_GET_VARS['method'];
}
^^ *** This bit works fine *** ^^
if($action=="add")
{
$headline = $HTTP_GET_VARS['txtHeadlin
$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[
{
$action = $HTTP_POST_VARS['method'];
}
^^ *** This bit works fine *** ^^
if($action=="add")
{
$headline = $HTTP_POST_VARS['txtHeadli
$story = $HTTP_POST_VARS['txtStory'
.......etc.......
ASKER
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
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
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>  ;<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['txtHeadlin e'];
$story = $HTTP_GET_VARS['txtStory'] ;
.......etc.......
************************** ********** ********** ********** ****
**************************
<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
<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['
{
$action = $HTTP_GET_VARS['method'];
}
^^ *** This bit works fine *** ^^
if($action=="add")
{
$headline = $HTTP_GET_VARS['txtHeadlin
$story = $HTTP_GET_VARS['txtStory']
.......etc.......
**************************
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=d onews&meth od=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>
<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();
?>
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=d
Headline<br>
<input type=textbox name=txtHeadline>
<br>
Story<br>
<TEXTAREA rows=10 cols=50 id=textarea1 name="txtStory"></TEXTAREA
<br>
<br>
<input type=submit value="Submit news">
</body>
</html>
AFRAME.PHP --------------------------
<?
if(!empty($HTTP_GET_VARS['
{
$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();
?>
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked!!
I didnt realise you could turn off register globals just like that!!!
Thank you very much!
I didnt realise you could turn off register globals just like that!!!
Thank you very much!
No Prob :)
"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;