?
Solved

PHP post var are "lost"

Posted on 2004-10-06
15
Medium Priority
?
958 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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
 
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 1000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

801 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