Form value passing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spanders
Forum Newbie
Posts: 7
Joined: Thu Jan 08, 2004 2:52 pm

Form value passing

Post by spanders »

I think I'm looking for help with a php.ini or version problem here, as my code works on one server but does not work on a different one.

Working server: RedHat Linux 7.2, PHP 4.3.4, Apache 1.3.27
Problem server: RedHat Linux 9, PHP 4.2.2, Apache 2.0.40

The code for a file called proccess.php:

Code: Select all

<html>
<head>

<script language=JavaScript type="text/javascript">
<!--
function updatepage(x) &#123;
        formname.currentpage.value = x;
        document.formname.submit();
&#125;
-->
</script>

<title>Title</title>
</head>
<body>

<form method="POST" name="formname" action="process.php">
<?php

        $currentpage = $_POST&#1111;"currentpage"];
        echo "currentpage = $currentpage <p>\n";
        echo "<input type='hidden' name='currentpage' value='$currentpage'>\n";

?>
<input type='button' value='add new' name='add' onClick="updatepage(1)"></p>
</form>
</body>
</html>
On the working server the line

Code: Select all

echo "currentpage = $currentpage <p>\n";
displays

currentpage = 1

after clicking the button on the page. On the problem server something different is displayed

currentpage = 1currentpage=1

The correct value is being displayed, but the value contains the variable name itselft and the value again. Any thoughts on what might be causing this? Thanks.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

The code is incorrect.

It should be written as:

Code: Select all

echo 'currentpage = ' . $currentpage . '<p>\n';
Then you shouldn't see an error.
spanders
Forum Newbie
Posts: 7
Joined: Thu Jan 08, 2004 2:52 pm

Post by spanders »

I had already tried that way and had the same problem. The reason I did not post that line of code is because I've been told more and more that it requires the register_globals setting in php.ini to be turned On and that is not recommended for security reasons. So I'm trying to move away from coding that way.

The the posted version of the code works fine on the "working" server, as does your version when register_globals is turned on.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Actually, there's nothing wrong with

Code: Select all

echo "currentpage = $currentpage &lt;p&gt;\n";
The line

Code: Select all

echo "&lt;input type='hidden' name='currentpage' value='$currentpage'&gt;\n";
should be

Code: Select all

echo "&lt;input type="hidden" name="currentpage" value="$currentpage"&gt;\n";
according to W3C HTML standards (tags attributes should be inbetween double quotes).

Corrections made, could you please insert these lines between </form> and </body>:

Code: Select all

</form>
<pre><?php
print_r($_POST); // [php_man]print_r[/php_man]()
?></pre>
</body>
and show us what both servers print.

Cheers,
Scorphus.
spanders
Forum Newbie
Posts: 7
Joined: Thu Jan 08, 2004 2:52 pm

Post by spanders »

scorphus's corrections added

output from working server:

before clicking button

currentpage =

BUTTON

Array
(
)



after clicking button

currentpage = 1


Array
(
[currentpage] => 1
)



On "bad" server

before clicking button

currentpage =


Array
(
)


after clicking button

currentpage = 1currentpage=1


Array
(
[currentpage] => 1currentpage=1
)
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

  • Please run the following piece of code on both servers:

    Code: Select all

    <?php
    echo '<pre>';
    echo 'PHP Version: '.phpversion()."\n";
    echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
    echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
    echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
    echo '</pre>';
    ?>
    and show us the output.
  • Are you testing both servers using the same machine and browser?
Thanks,
Sco.
spanders
Forum Newbie
Posts: 7
Joined: Thu Jan 08, 2004 2:52 pm

Post by spanders »

Correct, same browser, same PC to view both pages.

Good machine:
PHP Version: 4.1.2
Display Errors: On
Error Level: Not E_ALL
Register Globals: On

Bad machine:
PHP Version: 4.2.2
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Thanks for supplying the information. Unfortunately I can't see what should be going wrong, but I suspect from Apache 2.0.40 as it is at version 2.0.48 and there were many bug fixes since 2.0.40: http://ftp.pucpr.br/apache/httpd/CHANGES_2.0. You could try to update it.

Well, I hope some more experienced user may help you further.

Regards,
Scorphus.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

It's a bug in that version of apache2 that causes post'ed variables to be repeated.

http://bugs.php.net/bug.php?id=18648
Post Reply