Jump to content

adam1984

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

adam1984's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That was exactly what I was looking for. Thank you very much for the help, always appreciated!
  2. I created a form that accepts a user's first and last name, and also a script that saves this data to a text file. After each time a user submits the form, the entry is then written to a new line in my txt document (I'm using the \n to achieve this) That part really wasn't a problem. It's the second half of what I'm trying to do that's causing a little confusion. I want to print a summary that includes the number of lines in my text file, as well as the file's size. You'll see from my code that I have been able to do everything except summarize the number of lines in my text file .Any help would be very much appreciated.. here is the code I am working with, and I thank you in advance: ------------------------------------------------ <?php $filename="people_processed.txt"; $fp = fopen ($filename, "r") or die("Couldn't open $filename"); while (! feof($fp)) { $line = fgets($fp, 1024); print "$line<br />"; } // Below is code that will tell me how // big my file size is getting. print "<br />"; print "<br />"; print "The file size of people_processed.txt is "; print filesize("people_processed.txt"); print " bytes." ?>
  3. Haha, you are awesome. Thank you. I have tried the \n and have been working on this for hours. Very much appreciate it. Am I going to find wordpad more useful in the future as well?
  4. roopurt18>> I tried that but i'm not seeing the result :'( Is it because my people_processed file is a .txt? When I open the file I still see each name just running into eachother... would it help if people_processed was an .html file? I also tried creating a function and storing it in a variable to try it that way, but i was having trouble with that too.....
  5. Below is the code I have asking a user for their first and last name. After they submit, it saves the input to a separate file. My code works, but my processed file doesn't look pretty. Here is where I am having the trouble. For instance, if the user types in Bruce Willis, and then my next user types in Quentin Tarantino.. my .txt file where the names are written will look like this: --------------------------- Bruce Willis Quentin Tarantino --------------------------- Ideally, I would like a line break between each name. That would make it easier for me to "count lines" of the .txt file later to identify how many users have inputted names. Here is my code if anyone is available to give me some tips on how I could achieve this. Thank you in advance!! <html> <head> </title> </title> </head> <body> <?php $first= $_POST['firstname']; $last = $_POST['lastname']; $fullname= "$first $last "; $filename="people_processed.txt"; $fp = fopen($filename, "a" ) or die("Couldn't open file"); fwrite($fp, $fullname); fclose($fp); } else { $error = "You didn't enter a required field"; } } ?> <?php echo $error; ?> <form method="post" action=""> <input type="text" name="firstname" id="firstname" /> <input type="text" name="lastname" id="lastname" /> <input type="submit" name="submit" id="submit" /> </form> </body> </html>
  6. Thank you both very much!! Much appreciated!!
  7. So what I would like to do is create a form that accepts a user's first and last name. And create a script that saves this data to a file. I know how to write to a file, in the below example I would have saved my user input to variables in order to write them to a new file. ----------------------------------------------------- $fp = fopen(people_processed.txt, "w" ) or die("Couldn't open file"); fwrite($fp, $firstname $lastname); fclose($fp); ----------------------------------------------------- I am just lost on where to put this code. Would it go somewhere within my submit button? ???
  8. Well I'll keep on grinding at it then.
  9. Crayon-Violent, although I'm sure knows MUCH more about PHP than myself. Doesn't know anything about me, personally. Thanks again!
  10. Anti-Moronic, Thank you very much. I appreciate the help, honestly. For the record, since Violent whoever does not believe me, the book I have is SAMS TEACH YOURSELF PHP by Matt Zandstra. I'm about half way through it and this chapter introduces objects and classes, methods, constructs, etc. I'm very honest, and have been straight up about every post I've ever written on here. So again, Anti-Moronic, thank you very much for the help. SOLVED.
  11. Hey Asshole, I don't have a teacher, or professor, I'm not taking any class. I picked up a book from the store and am trying to learn. I read the chapter, and am having a little trouble with this exercise.
  12. Haha, no I'm sorry. I really don't have a shitty attitude towards your response. Every time I've posted on here I've said thanks and been thankful for any and all help I've gotten with PHP. I guess I'm just confused on where to put the code. I'm just trying to understand!!! Please reconsider.
  13. No I guess that didn't help me out too much? Where do I put that code? Are you willing to post the entire code I need inside my php tags?
  14. Here is my exercise: Create a class called baseCalc() that stores two numbers as properties. Give it a calculate() method that prints the numbers to the browsers. Alright, so that's it! Here is my code so far: <?php class baseCalc { //Properties public $number1 = 20; public $number2 = 80; //Method public function calculate($number1, $number2) { print $number1; print $number2; } } calculate(); ?> When I run this in the browser, I get an error message. It doesn't like when I call the calcuate() function/method. What am I doing wrong? Sincerely, ad Man
×
×
  • 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.