Jump to content


Photo

multi-part form


  • Please log in to reply
8 replies to this topic

#1 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 16 July 2006 - 10:17 PM

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:

Warning Cannot modify header information - headers already sent by (output started at /home/myaccountname/public_html/config.php:28) in /home/myaccountname/public_html/formhandler.php on line 57

(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 cookies
if (!empty($id)) setcookie('authcode', $id, time() + 3600*24*365, '/');
}

Where line 57 is:
if (!empty($id)) setcookie('authcode', $id, time() + 3600*24*365, '/');

The rest of the formhandler is:

}
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 file
if ($_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










#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 16 July 2006 - 10:22 PM

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.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 18 July 2006 - 11:08 AM

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...




#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 July 2006 - 11:30 AM

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).

//Invalid example:
<?php
echo("Something");
setcookie("1","1","1"); //will give a: "Headers already sent" error.
?>


//Valid example:
<?php
setcookie("1","1","1");
echo("Something");
?>


Orio.
Think you're smarty?

(Gone until 20 to November)

#5 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 18 July 2006 - 01:48 PM

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?

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 July 2006 - 01:59 PM

Then you must have either:
1) A whitespace or any char before your opening "<?php"
2) Something printed/echoed in in config.php
3) A whitespace or any char before your opening "<?php" or your closing "?>" in config.php

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 18 July 2006 - 02:30 PM

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?

#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 July 2006 - 04:40 PM

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.
Think you're smarty?

(Gone until 20 to November)

#9 russia5

russia5
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 20 July 2006 - 11:18 AM

Thankyou very much!  I got it.  White space was on the bottom of my config.php  I very much appreciate your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users