PHP form not submitting properly

software development

#1

Hey, folks:

For a superhero-themed website, I put together a simple PHP-based game, where you can challenge your friends to a superhero battle by e-mail. You can find it here. It’s been up for a few months now, and seems to work fine.

Now I’m putting together a new website with a wizard theme. I’d like to just take the superhero challenge, put it up on my new site, and change the text to make it wizard-themed. But for some reason, when I copy the PHP file over to my new site, it’s not working. For some reason, one of the forms is failing to pass the information along, resulting in an error message.

You can find the game on the new site here. Nothing has changed in the PHP, and the first form submits just fine–but even if you fill out the second form completely, you get an error message warning you that the information is not complete. Somehow, that second stage form is not passing the info along.

Can anybody help me figure out what has changed?

Here is the relevant form:

[quote]

As the challenger, you get the drop on <?php echo "$challenged_realname"?>, and
attack from a distance.

What is the name of the superpower you attack with (e.g. “laser-fist,” “Giggle of Death,” etc)?

What kind of attack is this?

Explosive
Focused like a laserbeam
Stealthily sneaky, sneakily stealthy, or some combination thereof

Almost immediately, <?php echo "$challenged_realname"?> counterattacks. Better defend yourself!

What superpower will you use to defend yourself?

What does this power let you do far more effectively than mere mortals?

Throw up a shield
Move out of the way
Spin around before somebody can sneak up behind you

Enough of this long-distance combat!
You and <?php echo "$challenged_realname"?> leap at each other, engaging
in fearsome hand-to-hand combat.

What superpower do you use at close range?

If you were to engage in a lengthy interior monologue in the midst of combat, how might you describe this superpower?

More forceful than a falling rock!
Sharper than titanium scissors!
More enfolding than a slip of paper!

<INPUT NAME=challengetype TYPE=hidden VALUE="<?php echo "$challengetype"?>">
<INPUT NAME=challenged TYPE=hidden VALUE="<?php echo "$challenged"?>">
<INPUT NAME=challenger TYPE=hidden VALUE="<?php echo "$challenger"?>">
<INPUT NAME=challengesent TYPE=hidden VALUE="<?php echo "$challengesent"?>">
<INPUT NAME=challenged_supername TYPE=hidden VALUE="<?php echo "$challenged_supername"?>">
<INPUT NAME=challenged_email TYPE=hidden VALUE="<?php echo "$challenged_email"?>">
<INPUT NAME=challenged_realname TYPE=hidden VALUE="<?php echo "$challenged_realname"?>">
<INPUT NAME=challenger_realname TYPE=hidden VALUE="<?php echo "$challenger_realname"?>">
<INPUT NAME=challenger_supername TYPE=hidden VALUE="<?php echo "$challenger_supername"?>">
<INPUT NAME=challenger_email TYPE=hidden VALUE="<?php echo "$challenger_email"?>">
<INPUT NAME=reason TYPE=hidden VALUE="<?php echo "$reason"?>">
<INPUT NAME=other_reason TYPE=hidden VALUE="<?php echo "$other_reason"?>">
<INPUT NAME=battle_state TYPE=hidden VALUE="<?php echo "$battle_state"?>">
<INPUT NAME=opted_in TYPE=hidden VALUE="<?php echo "$opted_in"?>">

[/quote]

#2

You may wish to provide some more information to see if someone can help. Such as if you are using PHP5 or 4 and what are the error messages saying since the problem may lie in other .php files especially if you are using PHP_SELF entries.

Unless you have a lot of php files you may want to change the file-suffix to PHP4 to run it under version 4, in case there has been some corruption during file transfer.


Norm


#3

I know exactly what is wrong. Your script assumes that the register_globals is set to “on” in the php.ini file. Although this was the case in DreamHost PHP4 installations, they wisely chose to disable this feature for PHP5. Therefore, global variables like $challenged_realname are not being created.

You have two options:

  1. The best solution is to switch to using the $_POST superglobal array, which has a certain symmetry to it, does it not? Instead of simply referencing your POST variables with a dollar sign, you must address them like this: $_POST[‘challenged_realname’]

  2. Alternatively, you can use the extract() function to simulate the effect of register_globals. I would not do it this way, but it works if you are a lazy programmer who doesn’t care much for security. Put the following at the very top of your page:

if($_POST) extract($_POST);My final piece of advice would be to clean up your HTML. You should quote all attribute values, so change things like:<form METHOD=POST ACTION="challenge.php">in to:<form method="post" action="challenge.php">--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#4

Thanks for the tip. Here’s something very odd:

Just as an experimental tweak, I switched to $_POST in [/i]one, single line of code[/i]. And that seemed to fix everything. I have no idea why, but now everything is working. Very odd.

But, in any case, it’s working now. Thanks!