SirChick Posted August 28, 2007 Share Posted August 28, 2007 I have a form which when the submit button is pressed it should go to a different page.... but when i have an include to do with absolutely nothing relating to the page other than to display how much money the user has.. and what level they are it just refreshes the page rather than doing the relocation. If i remove the include how ever it works . Would any one know what sorta thing causes this so i can check it out ? Quote Link to comment Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 We need to see some code. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 ok, the two codes work when seperated but not when together. this is the include code: <? //connect include include("include.php"); //include to allow $row assignments include("homeloginvariables.php"); $Level = $row["Level"]; $Money = $row["MoneyInHand"]; //setting max courage $EXP = $row["CrimeExp"]; ?> <div id='bv_' style='position:absolute;left:30px;top:118px;width:200px;height:19px;z-index:12' align='center'> <font style='font-size:14px' color='#FFFFFF' face='Arial'><b>Level:<font color='#32CD32'> <?= $Level?></b></font></div> <div id='bv_' style='position:absolute;left:130px;top:118px;width:200px;height:19px;z-index:12' align='center'> <font style='font-size:14px' color='#FFFFFF' face='Arial'><b>Money: <font color='#32CD32'>£<?= $Money?></b></font></div> <img src="energymax.jpg" id="Image2" alt="" align="top" border="0" width="125" height="5" style="position:absolute;left:380px;top:130px;z-index:1"> <? //Energy Bar for user $MaxEnergy = $row["MaxEnergy"]; $CurrentEnergy = $row["CurrentEnergy"]; $height = 5; $width = 125; $NewCurrentEnergy = ($CurrentEnergy / $MaxEnergy) * $width; echo "<div id='bv_' style='position:absolute;left:340px;top:115px;width:200px;height:19px;z-index:12' align='center'>"; echo "<font style='font-size:12px' color='#FFFFFF' face='Arial'><b>Energy $CurrentEnergy/$MaxEnergy</b></font></div>"; echo "<img src='energycurrent.jpg' id='Image2' alt='' align='top' border='0' width='.$NewCurrentEnergy.'height='5' style='position:absolute;left:380px;top:130px;z-index:1'>"; ?> <img src="couragemax.jpg" id="Image2" alt="" align="top" border="0" width="125" height="5" style="position:absolute;left:580px;top:130px;z-index:1"> <? //courage bar for user $MaxCourage = $row["MaxCourage"]; $CurrentCourage = $row["CurrentCourage"]; $height = 5; $width = 125; $NewCurrentCourage = ($CurrentCourage / $MaxCourage) * $width; echo "<div id='bv_' style='position:absolute;left:543px;top:115px;width:200px;height:19px;z-index:12' align='center'>"; echo "<font style='font-size:12px' color='#FFFFFF' face='Arial'><b>Courage $CurrentCourage/$MaxCourage</b></font></div>"; echo "<img src='currentcourage.jpg' id='Image2' alt='' align='top' border='0' width='.$NewCurrentCourage.'height='5' style='position:absolute;left:580px;top:130px;z-index:1'>"; ?> <img src="maxhappy.jpg" id="Image2" alt="" align="top" border="0" width="125" height="5" style="position:absolute;left:780px;top:130px;z-index:1"> <? //happy bar for user $HouseType = $houserow["HouseType"]; $MaxHappy = $row["MaxHappy"]; $CurrentHappy = $row["CurrentHappy"]; $height = 5; $width = 125; $NewCurrentHappy = ($CurrentHappy / $MaxHappy) * $width; echo "<div id='bv_' style='position:absolute;left:740px;top:115px;width:200px;height:19px;z-index:12' align='center'>"; echo "<font style='font-size:12px' color='#FFFFFF' face='Arial'><b>Happy $CurrentHappy/$MaxHappy</b></font></div>"; echo "<img src='currenthappy.jpg' id='Image2' alt='' align='top' border='0' width='.$NewCurrentHappy.'height='5' style='position:absolute;left:780px;top:130px;z-index:1'>"; ?> This is the code that the user observes and interacts with: if (isset($_POST['ShowHouses'])) { session_start(); $Area = $_POST['RegionComboBox']; $StreetName = $_POST['StreetComboBox']; $_SESSION['Area'] = $Area; $_SESSION['Streetname'] = $StreetName ; If ($Area == " ") { Die ('You must select a region!'); } ElseIf ($StreetName == "") { Die ('You must select a street name!'); } Else{ //this only works when the include is not included header("Location: housepurchaselist.php"); } Quote Link to comment Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 And how do these two files relate? You need to help us help you. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 well the first include just displays the user's energy bar happy bar and courage bar money and their level... which is a global include every page displays this. the next code which is the page the user is viewing is "buy house" page which the user selects the region and street which once picked, the locate takes the user to the next page, which shows available houses for their choice. It all works but if i have the energy bar etc showing on the page (which is also globally shown on every page of the entire site) this page doesn't seem to get along with it too well.. cos it cancels out the if statement at the start of the php of the latter script shown above. But i have used the exact same if statement as shown below in this post with the energy bar included and they work fine but not this one, which is why im not even sure where to begin to look. Referring to this if : if (isset($_POST['ShowHouses'])) { instead of going through that "if" and eventually doing this "header("Location: housepurchaselist.php");" it just refreshes the page and shows the same page with no errors shown. And also the transaction never occurred as i echoed the variables and they were all blank. Quote Link to comment Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 Are you sure its just not the call to header() that isn't working? You can't output anything to the browser (including any html) prior to calling the header() function. If you had error reporting turned on you would see an error. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 error reporting is deffinatly on. But surely the header call would have to be last because it only goes to the new location when validation has been successful first? Or have i misunderstood you ? Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 bump Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 You can have code before header(), but not output to the screen. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 If ($Area == " ") { Die ('You must select a region!'); } ElseIf ($StreetName == "") { Die ('You must select a street name!'); } Else{ //this only works when the include is not included header("Location: housepurchaselist.php"); So how would i logically do this so that the validation occurs and the header being afterwards? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 something in the include must be printing to the screen. Or have a space at the beginning or end of the file. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 well loads of things are being printed onto the screen from the include (the first script provided) shows that. But i use the include on every page on the site. So i'm still not following too well with this as i've not done anything different to many other pages that have this sort of thing? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Then you can't use the include on that page. Header() HAS to be called before any output. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 what methods are there around this then cos the energy bar include is kinda needed. but it still needs to redirect upon the button being pressed.. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Make your processing a seperate page, with NO html. It just processes. Then when it's DONE, it redirects to your normal page with your HTML. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 so itll be like: when isset go to process.php then in process.php go to result.php once complete? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 no. Make the form go to process.php. Otherwise you'll just have the same problem you do now. Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 28, 2007 Author Share Posted August 28, 2007 argh i see! i got it to work! thankyou jesi! Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Yay! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.