PHP Update Not Working in IE?

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
carleihar
Forum Commoner
Posts: 36
Joined: Fri Nov 13, 2009 5:59 pm

PHP Update Not Working in IE?

Post by carleihar »

For some reason this code is not completely working in IE. The link for feeding all the horses work, but feeding each individual horse does not work in IE, but it works in Firefox and Safari. Could any one explain this bug to me? Also, as I'm new to programming, could someone tell me if they thought this code was effectively written? There may be a way easier way to do what I'm trying to do. I know the JavaScript location is probably not the best programming technique, but I don't want the user to be able to refresh the code and POST just doesn't seem to be working with me. Thanks in advance!

Code: Select all

<?php

require_once('includes/mysqli_connect.php');
include('includes/config.inc.php');


include ('includes/header01.inc.php');


/**********************Find Hay Price**********************/

$q = "SELECT hayprice FROM worldvariables WHERE date='$today'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
		
if (mysqli_num_rows($r) == 1) { // Retrieve the user ID:

	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
	
	$hayprice = $row['hayprice'];
	
	}
	
} else {


$hayprice = rand(2, 12);

$q = "INSERT INTO worldvariables (hayprice, date) VALUES ('$hayprice', '$today')";
$r = @mysqli_query ($dbc, $q) or trigger_error(mysqli_error($dbc));
if ($r == FALSE) { 

	echo '<p class="error">Sorry, there was an error. Please contact an Administrator.</p>';
	echo '</div>';
	include ('footer01.inc.php');
	exit();  
}


}


if (isset($hayprice)) {

	echo '<h3>Today\'s Hay Price is: $';
	
	echo number_format($hayprice, 2);
	
	echo ' per bale.</h3>';

} else {
	
	echo '<p class="error">There was an error getting today\'s hayprice. Please contact an Administrator.</p>';
}

/**********************Find Hay Price*********************

/**********************Change Hunger**********************/

$q = "SELECT horse_id, date_fed, hunger, date_changed FROM hunger WHERE user_name='{$_COOKIE['username']}'";           
$r = @mysqli_query ($dbc, $q); // Run the query.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
	$date_fed=$row['date_fed'];
	$horse_id=$row['horse_id'];
	$date_changed=$row['date_changed'];
	$hunger=$row['hunger'];
	
	getHunger($date_fed, $horse_id, $hunger, $date_changed);
	
	
}	

/**********************Change Hunger**********************/




/**********************If Button Was Clicked**********************/
		   
if(isset($_GET['all'])){
	   
	$q = "SELECT horse_id, hunger FROM hunger WHERE user_name='{$_COOKIE['username']}'";           
$r = @mysqli_query ($dbc, $q); // Run the query.

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

	$horse_id=$row['horse_id'];
	$hunger=$row['hunger'];

	$hunger = $hunger + 1;
	
	if ($hunger > 10) {
		$hunger = 10;
	}
	
	if ($hunger < 0) {
		$hunger = 0;
	}
	
	$t = "UPDATE hunger SET date_fed='$today', hunger='$hunger' WHERE user_name='{$_COOKIE['username']}' AND horse_id='$horse_id'";
	$p = @mysqli_query($dbc, $t);
	
	
	$money = getUsersMoney();
	$money = $money - $hayprice;
	
	$y = "UPDATE users SET money='$money' WHERE username='{$_COOKIE['username']}'";
	$e = @mysqli_query($dbc, $y);
	
	if ($e == FALSE) {
		
		echo 'Sorry, there was an error.';
		
		exit();		
		
		}
	
	   
	} 
	
	?>
	
	<script language="javascript">
				
	window.location = "feedhorses.php";
				
	</script>
    
	<?php

	
} //end submit get

/**********************If Button Was Clicked**********************/




/**********************If Link Was Clicked**********************/

if(isset($_GET['one'])){

	
	$q = "SELECT hunger FROM hunger WHERE user_name='{$_COOKIE['username']}' AND horse_id='" . $_GET['feed'] . "'";           
	$r = @mysqli_query ($dbc, $q); // Run the query.

	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

	
		$hunger=$row['hunger'];
			   
		$hunger = $hunger + 1;
		
		if ($hunger > 10) {
			$hunger = 10;
		}
		
		if ($hunger < 0) {
			$hunger = 0;
		}
		
		$t = "UPDATE hunger SET date_fed='$today', hunger='$hunger' WHERE user_name='{$_COOKIE['username']}' AND horse_id='" . $_GET['feed'] . "'";
		$p = @mysqli_query($dbc, $t);
		
		
		$money = getUsersMoney();
		$money = $money - $hayprice;
		
		$y = "UPDATE users SET money='$money' WHERE username='{$_COOKIE['username']}'";
		$e = @mysqli_query($dbc, $y);
		
		if ($e == FALSE) {
			
			echo 'Sorry, there was an error.';
			
			exit();		
		
		}
	

	} //end while loop
	
	
	?>
	
	<script language="javascript">
				
	window.location = "feedhorses.php";
				
	</script>
    
	<?php
	

} //end submit get

/**********************If Link Was Clicked**********************/






/*****************************Page***************************/
echo'<table width=500px class="centerElement" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th>Horse Name</th>
    <th>Hunger</th>
    <th>Date Last Fed</th>
  </tr>';

$q = "SELECT horse_name, horse_id, date_fed, hunger, date_changed FROM hunger WHERE user_name='{$_COOKIE['username']}'";           
$r = @mysqli_query ($dbc, $q); // Run the query.

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {


	$date_fed=$row['date_fed'];
	$horse_id=$row['horse_id'];
	$horse_name=$row['horse_name'];
	$hunger=$row['hunger'];
	$date_changed=$row['date_changed'];
			
	echo '<tr>
		<td>' . $horse_name . '</td>
		<td>' . $hunger . '</td>';
	echo '<td><form action="" method="GET">';  
	echo '<input name="one" type="submit" value="Feed Horse">
		  <input name="feed" type="hidden" value="' . $horse_id . '"';  
	echo '</form></td>';  
	echo '</tr>';

}	

echo '<tr><td colspan=3><form action="" method="GET">';  
echo '<input name="all" type="submit" value="Feed All Horses"><br />';  
echo '</form></td></tr>';  

echo'</table>';		   
			   

/*****************************Page***************************/




include('includes/footer01.inc.php');

?>
solid
Forum Commoner
Posts: 28
Joined: Wed Aug 12, 2009 11:56 am

Re: PHP Update Not Working in IE?

Post by solid »

You are missing the closing arrow (>) for the 'feed' input tag. Firefox and Safari are more forgiving than IE.
carleihar
Forum Commoner
Posts: 36
Joined: Fri Nov 13, 2009 5:59 pm

Re: PHP Update Not Working in IE?

Post by carleihar »

Thanks so much!
Post Reply