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
https://forums.phpfreaks.com/topic/93939-wont-work-in-ie/#findComment-481407
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
https://forums.phpfreaks.com/topic/93939-wont-work-in-ie/#findComment-481531
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
https://forums.phpfreaks.com/topic/93939-wont-work-in-ie/#findComment-481550
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
https://forums.phpfreaks.com/topic/93939-wont-work-in-ie/#findComment-481702
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.