Worqy Posted April 3, 2010 Share Posted April 3, 2010 Hi. I get a error message from this code: Error: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Game\S1\checkbuild.php:12) in C:\xampp\htdocs\Game\S1\checkbuild.php on line 50 Code: <?php Session_start(); if($_SESSION['LoginS1'] == false) { header('Location:login.php'); } else { $fieldid = $_SESSION['fieldID']; // Check is player has enought resources $field = "field" . $fieldid; echo "Field ID " . $fieldid; echo "<br>"; $level = $_SESSION['level']; $nextlevel = $level + 1; // Include include 'buildings.config.php'; // Connect to server and select database $connect = mysql_connect("$host","$username","$password")or die("cannot connect"); mysql_select_db("s1-prices")or die("cannot select Database"); $sql = mysql_query("SELECT * FROM $field WHERE level='$nextlevel'") or die(mysql_error()); while($data = mysql_fetch_array( $sql )) { $three = $data['three']; $clay = $data['clay']; $iron = $data['iron']; $wheat = $data['wheat']; echo "Next level: "; echo "<b>" . $nextlevel . "</b> "; echo "<br>"; echo "Price for level " . $nextlevel; echo $three . " "; echo $clay . " "; echo $iron . " "; echo $wheat . " "; } $villageID = $_SESSION['villageID']; mysql_close($connect); $connect2 = mysql_connect("$host","$username","$password")or die("cannot connect"); mysql_select_db("s1-overall")or die("cannot select Database"); $sql2 = mysql_query("SELECT * FROM resources") or die(mysql_error()); while($data2 = mysql_fetch_array( $sql2 )) { if($data2['three'] > $three && $data2['clay'] > $clay && $data2['iron'] > $iron && $data2['clay'] > $clay) { //Build } else { header('Location:build.php'); } } } ?> Quote Link to comment Share on other sites More sharing options...
Lukeidiot Posted April 3, 2010 Share Posted April 3, 2010 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
jmajeremy Posted April 4, 2010 Share Posted April 4, 2010 The header information always has to be sent to the client before anything else. You can't echo() things to the client, and then redirect them. You could theoretically get around this by using output buffering, but I would seriously reconsider my logic, since there should be no need to output text to the browser before header information. 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.