Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109

    Unanswered: php writing in text file!!

    i have make a form which coding is this
    <form name="form1" method="post" action="submit.php">
    <p>
    <input name="cname" type="text" id="name">
    </p>
    <p>
    <input name="cemail" type="text" id="email">
    </p>
    <p>
    <input name="ccomments" type="text" id="comments">
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>



    and i make a file call submit.php which coding is this

    <?php
    $name=$_post['name'];
    $email=$_post['email'];
    $comment=$_post['comments'];
    $dat=date("m/d/y");
    $coding="<table width=768 height=134 border=3 cellpadding=0 cellspacing=0 bordercolor=#666666 gcolor=#FFFFCC><tr><td width=341 height=22><B>BY :</B><font color=#0000FF><B>.$name.</B></font></td><td width=286><b>$dat</b></td><td width=141 rowspan=2><B>.$_time.</B></td></tr><tr><td width=341 height=21>&nbsp;</td><td>&nbsp;</td></tr><tr><td colspan=3><B><font color=#0000FF>.$comments.</font></B></td></tr><tr><td height=37 colspan=3><p align=right><font size=4><B>.$email.</B></font></p></td></tr></table>";
    $myfile="comments.txt";
    $fh=fopen($myfile,'a');
    $string="$coding";
    Fwrite($fh,$string);
    fclose($fh);
    ?>

    i want that it trace the table coding in text file and it do it but it has a problem that it doesn't write the form content inside the table it create a table in view form but don't show the comments name and email can any body tell it to me that what's wrong with this coding

    i write this .$comment. it write two dots but don't write comments form which is shown in the form tell me the problem

  2. #2
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    is there any answer please tell it to me please

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what I use to write a PDF file is
    PHP Code:
      $dir =  './adirectory'
      
    //save the file
      //create the directory with appropriate permissions if it doesn't already exist
      
    if (!file_exists($dir)) { mkdir ($dir,0777);} 
      
    //build the filename 
      
    $fname tempnam($dir.'/','<MyFileName>'.date("YmdHis")).'.<MyExtension>';
      
    //opn the file for write access
      
    $fp fopen($fname,'w');
      
    //dump all the crap from MyFileContents to the file
      
    fwrite($fp,$MyFileContents);
      
    //close the file
      
    fclose($fp); 
    where
    $MyFileContents is the stuff to be written to file
    <MyFileName> is the name of the site.. this creates a file name with the timestamp added to make each file unique
    <MyExtension> is the extension of the file (in this case I'd use PDF)
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    Quote Originally Posted by healdem
    what I use to write a PDF file is
    PHP Code:
      $dir =  './adirectory'
      
    //save the file
      //create the directory with appropriate permissions if it doesn't already exist
      
    if (!file_exists($dir)) { mkdir ($dir,0777);} 
      
    //build the filename 
      
    $fname tempnam($dir.'/','<MyFileName>'.date("YmdHis")).'.<MyExtension>';
      
    //opn the file for write access
      
    $fp fopen($fname,'w');
      
    //dump all the crap from MyFileContents to the file
      
    fwrite($fp,$MyFileContents);
      
    //close the file
      
    fclose($fp); 
    where
    $MyFileContents is the stuff to be written to file
    <MyFileName> is the name of the site.. this creates a file name with the timestamp added to make each file unique
    <MyExtension> is the extension of the file (in this case I'd use PDF)
    can you tell me that why it couldn't write any thing in my guestbook
    when i write the variable which i declare for the contents get from form field it couldn't write in the text file instead it write date and any other text which i write in the place of variable

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by don_log
    is there any answer please tell it to me please
    You should learn how to test your code properly. If you print out the values of your variables straight after you set them then you'll know whether the problem occurs there ie:
    Code:
    <?php
    $name=$_post['name'];
    $email=$_post['email'];
    $comment=$_post['comments'];
    $dat=date("m/d/y");
    print( "name=$name, email=$email, comment=$comment, dat=$dat\n" );
    You may find that your variables aren't being set at all in which case I'd use _POST as the array name. If that doesn't work then I'd try _GET just in case the form is set up that way.

    It might be worth looking at the file you're using. You don't specify what directory the file should go in or whether you have permission to write to this directory. Perhaps change it to :
    Code:
    $myfile="/tmp/comments.txt";
    Where do you start and end the html code ie "<html><body>" etc ?
    Why do you print "." around each variable value?

  6. #6
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Simply put, you have a typo
    $comments is used inside the table string, but $comment is the name of the variable. Notice the difference?

    Also, you don't need the .$comment. just $comment because you're using double quotes (and you're not even exiting the string before attempting to append, hence the 2 dots).

Posting Permissions

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