SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Stupid Question

  1. #1
    SitePoint Enthusiast weich1213's Avatar
    Join Date
    Nov 2008
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Stupid Question

    This is probably a stupid question. I hope it is so it can be answered, but I'm trying to redirect to a new page with my php script but I get the following error message:
    Warning: Cannot modify header information - headers already sent by (output started at /home/www/eclipsedesignca.com/includes/write_to_a_flat_file.php:24) in /home/www/eclipsedesignca.com/index.php on line 59
    can anyone tell me what I'm doing wrong. I don't know php, i'm just experimenting from a book.

    the part of the script I'm trying to use to redirect it looks like this:


    /* set up variables for use in the mail function */
    $destination_email="sendmail@weich1213.com";
    $email_subject="My PHP form info";
    /*assemble the email body text in a variable */
    $email_body = "$first_name\n$last_name\n$phone_number\n$message\n$email";

    if (!$error_msg) { //if no errors
    /* then send the email using PHP's mail function */
    mail ($destination_email, $email_subject, $email_body);
    //write data to a flat file
    writeToFile ($first_name, $last_name, $email, $phone_number, $message);
    /* redirect to a new page - we are done on this page */
    print ("redirecting...");
    header ('Location: index.php');
    /* stop the script right here */
    exit();
    }
    } /*end of if post submitted */

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    output started in write_to_a_flat_file.php on line 24
    this can be:
    space here before the php start tag<?php

    check write_to_a_flat_file.php at line 24
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Enthusiast weich1213's Avatar
    Join Date
    Nov 2008
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no there is no line 24 in that file, it looks like this:

    <?php
    /* writing into a text file */

    // create variables for file path and file name
    function writeToFile ($first_name,$last_name, $email, $phone_number, $message){
    $myFilePath = "../files/";
    $myFileName = "form_data_file.txt";




    $form_data = $first_name . "\t" . $last_name . "\t" . $email . "\t" . $phone_number . "\t" .$message . "\n";
    $myPointer = fopen($myFilePath.$myFileName, "a+");
    fputs ($myPointer, $form_data);
    fclose($myPointer);
    }

    ?>

  4. #4
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the curly bracket * } * at the end of the file for?

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the function it's ok
    PHP Code:
    /* writing into a text file */
    // create variables for file path and file name
    function writeToFile$first_name$last_name$email$phone_number$message )
    {
        
    $myFilePath "../files/";
        
    $myFileName "form_data_file.txt";
        
    $form_data $first_name "\t" $last_name "\t" $email "\t" $phone_number "\t" $message "\n";
        
    $myPointer fopen$myFilePath $myFileName"a+" );
        
    fputs$myPointer$form_data );
        
    fclose$myPointer );
    }

    writeToFile("x","y","z","1","foo"); 
    actually it's an error and that is the output

    check if the path is correct
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •