Results 1 to 5 of 5

Thread: Bit of basic PHP help, please chaps?

  1. #1
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value

    Bit of basic PHP help, please chaps?

    Currently doing network systems at college, and I'm trying to figure out how to append a date/time doodah to a text file. Html:

    Code:
    <html>
    <head>	
    <title>Student Information Form</title>
    </head>
    <body bgcolor="#000000" text="#ffffff" link="#0000ff" vlink"#800080" alink="#ff0000">
    	<form action="/cgi-bin/assignment1.php" method="post">
    	
    		<H2>Student Information Form</H2>
    			
    			<HR>
    			<B>Student Information:</B>
    			<BR><I>First Name </I><input type="text" name="firstname" size="12" maxlength="15">
    			<BR><I>Surname </I><input type="text" name="surname" size="12" maxlength="15">
    			<BR><I>Date of Birth </I><input type="text" name="dob" size="12" maxlength="10">
    			<BR><I>House Number </I><input type="text" name="housenumber" size="12" 
    
    maxlength="10">
    			<BR><I>Street Name </I><input type="text" name="streetname" size="12" 
    
    maxlength="20">
    			<BR><I>Town/City </I><input type="text" name="towncity" size="12" maxlength="15">
    			<BR><I>Postcode </I><input type="text" name="postcode" size="12" maxlength="10">
    			<BR><I>Course Name </I><input type="text" name="course" size="12" maxlength="20">
    			<BR><I>Student ID. </I><input type="text" name="studentid" size="12" 
    
    maxlength="10">
    			<BR> 
    			<BR><input type="reset" value="Clear Form">  
    			<BR> 
    			<BR><input type="submit" value="Submit Information"> 
    			</form>
    			<HR>
    
    </body>
    </html>
    PHP Code:
    <html> 

      <head> 
        <title>Student Information Form</title> 
      </head> 

      <body> 

        <?php 

          
    print  "<BR>Your information has been received, and has been logged on: \n"
          echo 
    date ("j/m/Y ( H:i:s )");
          print  
    "<BR>Your completed form details are displayed below.\n"

              
    $firstname $_POST["firstname"]; 
              
    $surname $_POST["surname"]; 
              
    $dob $_POST["dob"]; 
        
    $housenumber $_POST["housenumber"];
        
    $streetname $_POST["streetname"];
        
    $towncity $_POST["towncity"];        
        
    $postcode $_POST["postcode"];
        
    $course $_POST["course"];
        
    $studentid $_POST["studentid"];            
        
              print  
    "<BR><BR>First name = $firstname\n"
              print  
    "<BR>Surname  = $surname\n"
              print  
    "<BR>Date of birth = $dob\n"
        print  
    "<BR>House Number = $housenumber\n"
        print  
    "<BR>Street Name = $streetname\n";
        print  
    "<BR>Town/City = $towncity\n";
        print  
    "<BR>Postcode = $postcode\n";
        print  
    "<BR>Course Name = $course\n";
        print  
    "<BR>Student ID. = $studentid\n";
          
        print  
    "<BR><BR>"
        
    $filename ='c:\temp\tmsfeedback.doc';
    $fp fopen$filename "a");
        
    fputs($fp,"\nFirstname=$firstname");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nSurname=$surname");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nDate of Birth=$dob");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nHouse Number=$housenumber");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nStreet Name=$streetname");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nTown/City=$towncity");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nPostcode=$postcode");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nCourse Name=$course");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\nStudent ID.=$studentid");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\n===============");
        
    fputs($fp,"\n===============");

    fclose($fp);
        
    ?> 

      </body> 

    </html>
    I'm fine with all the above, however I have to append a date for every entry in the text file. I've been using

    echo date ("j/m/Y ( H:i:s )");

    to show date/time in the feedback php form, but I can't figure how to append it.

    I'm guessing I'd have to create a local variable, but I have little clue how to do this other than with pre-defined html named variables, as shown above.

    Help, please?

  2. #2
    Senior Member
    Join Date
    Jul 2003
    Location
    Magrathea
    Posts
    201
    Thanks
    0
    Thanked
    0 times in 0 posts
    I think if I am understanding your problem correctly you will need to use '.'

    e.g.

    $test1="hello ";
    $test2="world";

    $test3=$test1 . $test2; // $test3 = "hello world"





    Therefore your fputs you could have

    $timestring = date ("j/m/Y ( H:i:s )");
    fputs($fp,$timestring . " Firstname=$firstname");



    or you could have a function to replace the fputs which always does this to save having that variable posted all over the place.

  3. #3
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    Thanks chap. I'll try it out when I get home, later

    Fingers crossed. Being a beginner again, eh? Hoohah

  4. #4
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    No need for multiple print or fputs statements. Also remember to check if the file was actually opened. Just use something similar to the code below

    PHP Code:
    <?php 
        
    echo "<br>Your information has been received, and has been logged on:
        <br>"
    .date ("j/m/Y ( H:i:s )")."
        <br>Your completed form details are displayed below
        <br><br>"

        
        
    $firstname $_POST["firstname"];
        
    $surname $_POST["surname"]; 
        
    $dob $_POST["dob"]; 
        
    $housenumber $_POST["housenumber"];
        
    $streetname $_POST["streetname"];
        
    $towncity $_POST["towncity"];        
        
    $postcode $_POST["postcode"];
        
    $course $_POST["course"];
        
    $studentid $_POST["studentid"];            
        
        echo 
    "<br><br>First name = $firstname
        <br>Surname  = 
    $surname
        <br>Date of birth = 
    $dob
        <br>House Number = 
    $housenumber
        <br>Street Name = 
    $streetname
        <br>Town/City = 
    $towncity
        <br>Postcode = 
    $postcode
        <br>Course Name = 
    $course
        <br>Student ID. = 
    $studentid
        <br><br>"

        
        
    $filename ='c:\temp\tmsfeedback.doc';
        
    // check to see if file was actually opened
        
    if ($fp fopen$filename "a"))
        {
            
    fputs($fp,"\nFirstname=$firstname
            \n===============
            \nSurname=
    $surname
            \n===============
            \nDate of Birth=
    $dob
            \n===============
            \nHouse Number=
    $housenumber
            \n===============
            \nStreet Name=
    $streetname
            \n===============
            \nTown/City=
    $towncity
            \n===============
            \nPostcode=
    $postcode
            \n===============
            \nCourse Name=
    $course
            \n===============
            \nStudent ID.=
    $studentid
            \n===============
            \n===============
            \n==============="
    );
            
            
    fclose($fp);
        } else {
            echo 
    "Could not open ".$filename;
        }
    ?>

  5. #5
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    Thank you, chaps. Got the script working very nicely, now. Currently working on one, now, that does the same thing, but appends to an sql database

    Both of your help is noted, and you're exempt from taxation for the annum to follow

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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