...

View Full Version : Page Refreshing



TrueG
03-10-2009, 09:54 PM
I have a script where you can go in hospital but when you click the button it just refreshes the page.



}elseif ($fetch->hospital == '0'){
if (strip_tags($_POST['Submit']) && strip_tags($_POST['units'])){
$units=intval(strip_tags($_POST['units']));
if ($units == 0 || !$units || ereg('[^0-9]',$units)){
print "Invalid amount.";
}elseif ($units != 0 && $units && !ereg('[^0-9]',$units)){
$price = $units * $cost;
if ($price > $fetch->money){
echo "It cost's ".makecomma($cost)." for $units hour's in hospital.";
}elseif ($price <= $fetch->money){
$new_money=$fetch->money - $price;
$new_health=$fetch->health + $units;
if ($fetch->health == "100"){
echo "You dont need to go into the hosptial!";
}else{
$ime1=$units*3600;
$new_time = time('Y-m-d h:i:s') + $ime1;
mysql_query("UPDATE accounts SET money='$new_money', htime='$new_time', hospital='1', hlong='$units' WHERE username='$username'");
echo "You are now in the hospital for $units hours!";
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=hospital.php">';
}}}}}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Hospital</title>
</head>
<link href="/style.css" rel="stylesheet" type="text/css">
<body>

<form name="form1" method="post" action="">
<table width="400" border="0" align="center" class="table1px" cellpadding="0" cellspacing="0">
<tr><td height="30" colspan="2" class="gradient">The Hospital</td></tr>
<tr>
<td width="51%" class="tableborder" align="right">Health wanted:</div></td>
<td width="49%" class="tableborder" align="left"><input name="hours" type="text" class="textbox" id="hours" size="7" maxlength="5"></td>
</tr>
<tr>
<td colspan="2" class="tableborder" align="center"><input name="heal" type="submit" class="custombutton" value="Go To Hospital"></td>
</tr>
</table>
<br>

TrueG
03-10-2009, 10:22 PM
Just refreshes the page :S

ninnypants
03-10-2009, 10:50 PM
it may be because you're echoing this

echo '<meta HTTP-EQUIV="REFRESH" content="0; url=hospital.php">';
above the head of the document.

You may want to try:

header("Location: ".$_SERVER['PHP_SELF']);

TrueG
03-10-2009, 11:10 PM
Nope just doesn't do any thing then

barkermn01
03-10-2009, 11:17 PM
first sort out you code how is any one supposed to read that!

Every time you use { all the lines before the } of the statement should be tabbed in or at less double spaced in use notepad++

E.G


while($hi != 'hi'){
if($hello != 'hello'){
echo 'hello not sent';
}
$hi = 'hi';
}


See make it easy to read and for others to help you

barkermn01
03-10-2009, 11:22 PM
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=hospital.php">';

This is creating a Redirect loop
fix it with


if($_GET['loop'] == '0'){
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=hospital.php?loop=1">';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum