Jump to content

Won't work in IE


ryeman98

Recommended Posts

Sorry about that, I kinda ran off too quick.

 

<?php
if ($_GET['act'] == "choose") {
echo "<form action='rps.php?act=result' method='post'>";
echo "<table align='center' width='10%' border='0'><tr><td align='left'>";
echo "<input type='image' name='choice' value='rock' src='../images/rock.gif'>";
echo "<input type='image' name='choice' value='paper' src='../images/paper.gif'>";
echo "<input type='image' name='choice' value='scissors' src='../images/scissors.gif'>";
echo "</td></tr></table>";
echo "</form>";

} elseif ($_GET['act'] == "result") {
$_SESSION['pageview'] = $_SESSION['pageview']+1;

if ($_SESSION['pageview'] > 1) {
	echo "<a href='/rules.php'>No cheating!</a>";
} else {
	$user_choice = $_POST['choice'];
	$comp = array("rock",
				"paper",
				"scissors");
	$rand_comp = rand(0, 2);
	$comp_choice = $comp[$rand_comp];

	echo "You chose: ". $user_choice ."<br />";
	echo "Comp chose: ". $comp_choice ."<br /><br />";
?>

 

As you can see, in IE ONLY, $user_choice is NULL. In Any other browser, it has what the user submitted.

 

Link to comment
Share on other sites

This is all IE's fault. Ha Ha.  This is a case where IE gets it right and other browsers do it wrong.

 

When an image submit is clicked, it properly acts like an image map and returns the x and y co-ordinates of the clicked point relative to the upper-left corner of the image.  If the image name is banana, then a POSTed form will provide the co-ordinates as $_POST['banana_x'] and $_POST['banana_y'].  $_POST['banana'] will not exist.

 

With multiple image submits each will, of course, need a different name not the same name and a different value.

Link to comment
Share on other sites

Try this:

<?php
if ($_GET['act'] == "choose") {
echo "<form action='rps.php?act=result' method='post'>";
echo "<table align='center' width='10%' border='0'><tr><td align='left'>";
echo "<input type='image' name='choice' value='rock' src='../images/rock.gif'>";
echo "<input type='image' name='choice' value='paper' src='../images/paper.gif'>";
echo "<input type='image' name='choice' value='scissors' src='../images/scissors.gif'>";
echo "</td></tr></table>";
echo "</form>";

} elseif ($_GET['act'] == "result") {
$_SESSION['pageview'] = $_SESSION['pageview']+1;
}	
if ($_SESSION['pageview'] > 1) {
	echo "<a href='/rules.php'>No cheating!</a>";
} else {
	$user_choice = $_POST['choice'];
	$comp = array("rock",
				"paper",
				"scissors");
	$rand_comp = rand(0, 2);
	$comp_choice = $comp[$rand_comp];

	echo "You chose: ". $user_choice ."<br />";
	echo "Comp chose: ". $comp_choice ."<br /><br />";
?>

Link to comment
Share on other sites

monkeybidz, just posting random code without stating what you changed or fixed in it does not help the OP now, nor anyone that happens to find the thread in the future with the same problem.

 

AndyB's post address the actual problem with the code. Also see this in the php manual - http://www.php.net/manual/en/faq.html.php#faq.html.form-image

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.