russia5 Posted July 16, 2006 Share Posted July 16, 2006 Hello... Please and Thx for any help you guys might have for me. I have a multi-part form that feeds to a MySQL The form seems to work okay, successfully delivering the text data of part 1 of the form to the table as well as the image urls which are on parts 2 thru 5 of the form, however, I am getting this error on submission of each part of the form:[b]Warning[/b] Cannot modify header information - headers already sent by (output started at /home/myaccountname/public_html/config.php:28) in /[b]home/myaccountname/public_html/formhandler.php[/b] on line [b]57[/b](see underscore below for line 57)Here is the first part of the form handler:<?php if (empty($_REQUEST['step'])) $step = 1; else $step = $_REQUEST['step'];if (empty($_POST['id'])) $id = 0; else $id = $_POST['id'];include_once ("config.php");if (!empty($_POST)){if ($step < 3) // insert/update info {$fields = $values = array();unset($_POST['Submit']);if (empty($_POST['id'])) {unset($_POST['id']);foreach ($_POST as $field=>$value){$fields[] = $field;$values[] = '"'.htmlspecialchars(trim($value)).'"';} $query = 'INSERT INTO Profile_submission ('.implode(',', $fields).') VALUES ('.implode(',',$values).')';mysql_query($query);$id = mysql_insert_id();# set cookiesif (!empty($id)) setcookie('authcode', $id, time() + 3600*24*365, '/'); }[u]Where line 57 is:[/u]if (!empty($id)) setcookie('authcode', $id, time() + 3600*24*365, '/');[u]The rest of the formhandler is:[/u]}else{$qryString = array();$currentID = $_POST['id'];unset($_POST['id']);foreach ($_POST as $field=>$value){$qryString[] = $field.' = "'.htmlspecialchars(trim($value)).'" ';} $query = 'UPDATE Profile_submission SET '.implode(',', $qryString).' WHERE sid = "'.$currentID.'"';mysql_query($query);}}else // upload photos{$uploaded_file ="";// move uploaded fileif ($_FILES['picture']['tmp_name'] != "none" and $_FILES['picture']['tmp_name'] != "") { $tmpname = rand(time()-10000, time()).".jpg";$uploaded_file = 'uploads/'.$tmpname;if (@move_uploaded_file($_FILES['picture']['tmp_name'], $uploaded_file)) {chmod($uploaded_file, 0777); } } $query = 'UPDATE Profile_submission SET picture'.($step-2).' = "'.$uploaded_file.'" WHERE sid = '.$id;mysql_query($query);}}elseif (!empty($_COOKIE['authcode'])){$query = 'SELECT * FROM Profile_submission WHERE sid = "'.$_COOKIE['authcode'].'"';$result = mysql_query($query);if (mysql_num_rows($result)){$profile = mysql_fetch_assoc($result);$id = $_COOKIE['authcode'];}}if ($step > 6) {header("Location: ");}This form use to work right without this error. I don't believe a change was made in the form or the handler, however, I could be wrong.Again, thanks for the help on this problem as well as all the help you have delivered to me in the past. russia5 Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/ Share on other sites More sharing options...
pixy Posted July 16, 2006 Share Posted July 16, 2006 You MUST setcookie(); before you load ANY information onto the page, or you will get this error.Please read the sticky in thread forum about "headers sent" before posting issues about headers. Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59092 Share on other sites More sharing options...
russia5 Posted July 18, 2006 Author Share Posted July 18, 2006 Thanks for your helpful response. After reading the thread you suggested and a couple more, I tryed some things but they did not work. Let me ask, when you setcookie() you are suppose to set it within the present formhandler script that it is in now, right? Second, I am not exactly sure where the data is considered loaded. Would an appropriate spot to setcookie() be below the beginning tag ie) <?php setcookie() ... My second guess, is right after <include config.php>Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59857 Share on other sites More sharing options...
Orio Posted July 18, 2006 Share Posted July 18, 2006 header fucntions, session functions and cookie functions must be used before the headers are being sent.What does this mean? That means that you got to use these functions before there is any output (using functions like echo() will output something).[code]//Invalid example:<?phpecho("Something");setcookie("1","1","1"); //will give a: "Headers already sent" error.?>//Valid example:<?phpsetcookie("1","1","1");echo("Something");?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59862 Share on other sites More sharing options...
russia5 Posted July 18, 2006 Author Share Posted July 18, 2006 That's what I would guess it to be. However, for the life of me, I do not see where I am outputting before setcookies() Line 57 Are my challenged eyes not picking something up that is apparrent to you? Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59883 Share on other sites More sharing options...
Orio Posted July 18, 2006 Share Posted July 18, 2006 Then you must have either:1) A whitespace or any char before your opening "<?php"2) Something printed/echoed in in config.php3) A whitespace or any char before your opening "<?php" or your closing "?>" in config.phpOrio. Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59886 Share on other sites More sharing options...
russia5 Posted July 18, 2006 Author Share Posted July 18, 2006 Very impressive knowledge! Thankyou very much! White space is defined, from my understanding, as space that is unoccupied by text within an HTML document. Since, the form handler is not in an HTML doc and niether is config.php, what is white space outside of php tags and how does one get rid of it? Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59900 Share on other sites More sharing options...
Orio Posted July 18, 2006 Share Posted July 18, 2006 A white space, like a regular space between words, but you just cant see it.Anyway, there's probbly a space hiding in this file or the config.php before the opening <?php or after the closing "?>".Orio. Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59957 Share on other sites More sharing options...
russia5 Posted July 20, 2006 Author Share Posted July 20, 2006 Thankyou very much! I got it. White space was on the bottom of my config.php I very much appreciate your help! Quote Link to comment https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-60937 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.