jeff5656 Posted November 21, 2008 Share Posted November 21, 2008 I get this error :Warning: Cannot modify header information - headers already sent by (ou..." Now I read that I get this error if there is any HTML prior to this command, but as you can see below, I don't have any HTML! So how do I correctly redirect after the following code is run? include "../connectdb.php"; $this_month=$_POST['which_month']; $query = "UPDATE staffsched SET "; $set = array(); foreach($_POST as $field => $value){ $field = mysql_real_escape_string($field); $value = mysql_real_escape_string($value); $set[] = "`{$field}` = '{$value}'"; } $query .= implode(", ",$set) . " WHERE `which_month` = '".$this_month."'"; mysql_query($query) or die(mysql_error()); header("Location: editcurrent.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/ Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 get rid of any white space before <?php Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694954 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 The error message tells you where the output is occurring that is preventing the header. The output can be anything and is not specifically just HTML. It can be a space, new-line, UTF-8 BOM, HTML... Post the whole error message and the code is mentions if you want any specific help. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694957 Share on other sites More sharing options...
phpSensei Posted November 21, 2008 Share Posted November 21, 2008 There is many spaces before that include file, and correct me if I'm wrong but is that where the header begins? anyways, I am wondering if this is possible in PHP $set[] = "`{$field}` = '{$value}'"; That seems completely off to me. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694970 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 the white space after <?php isn't important, as long as it isn#t print or echo etc.... That code looks fine, just adding a string made of two variables to an array? Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694975 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 Sticky time, please read... Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694976 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 There is nothing wrong with that line of code. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694981 Share on other sites More sharing options...
jeff5656 Posted November 21, 2008 Author Share Posted November 21, 2008 Sorry I see no spaces: The very very first line of this code (called commit.php) is <?php: <?php include "../connectdb.php"; $this_month=$_POST['which_month']; $query = "UPDATE staffsched SET "; $set = array(); foreach($_POST as $field => $value){ $field = mysql_real_escape_string($field); $value = mysql_real_escape_string($value); $set[] = "`{$field}` = '{$value}'"; } $query .= implode(", ",$set) . " WHERE `which_month` = '".$this_month."'"; mysql_query($query) or die(mysql_error()); header("Location: editcurrent.php"); ?> Here is the exact error message that someone requested: Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/jeffjn/html/connectdb.php:2) in /home/content/j/e/f/jeffjn/html/schedules/commit.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694993 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 Read the error output started at /home/content/j/e/f/jeffjn/html/connectdb.php:2 Something at or before line 2 in connectdb.php is causing output. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694999 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 Use this code, let the page load, and VIEW SOURCE to see if there is any output being generated. $this_month=$_POST['which_month']; die(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695012 Share on other sites More sharing options...
phpSensei Posted November 21, 2008 Share Posted November 21, 2008 There is nothing wrong with that line of code. If you are talking to me, I've never seen a variable being set like that with to '='s. Its okay, I learn something new everyday. Post the first few line of codes in the connectdb.php page. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695019 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 $set[] = "`{$field}` = '{$value}'"; The second equals is just part of a string, it has nothing to do with assigning a variable Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695026 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 He's not setting a variable, he is dynamically forming an sql UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695029 Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 Yes, by assigning a string in an array, and using that string as part of the query, I understand. Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695034 Share on other sites More sharing options...
phpSensei Posted November 21, 2008 Share Posted November 21, 2008 OH man im dumb, i didnt see the double quote. edit: I thought I saw this: $var = 'sdsads' = '{$dsf}' = $this; I need to grab my glasses Quote Link to comment https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-695040 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.