Jump to content

Recommended Posts

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 cookies
if (!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 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








Link to comment
https://forums.phpfreaks.com/topic/14796-multi-part-form/
Share on other sites

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


Link to comment
https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59857
Share on other sites

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:
<?php
echo("Something");
setcookie("1","1","1"); //will give a: "Headers already sent" error.
?>


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


Orio.
Link to comment
https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59862
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/14796-multi-part-form/#findComment-59900
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.