SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 43
  1. #1
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile The Simple Things

    This thread was made to help people who are getting started in php and just want to learn simple things jus tto fool around in in a personal page.

    My first questions is how to make a php page that sends data from a form to a text file. I've looked all over the internet, but I can't find any good help on this topic. Thanks to whoever helps myself along with others on the "Simple Things".

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at fwrite in the manual.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help With Strings

    Well that showed me just about everything I have learned. I need to know how to make that string the from data from a previous page.

    Example:

    <? echo $_POST['change'] ?>

    'change' obviously being the name of the text field from the previous page with the form in it. How do I convert that to a string?

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To convert that to a string, just do this:
    Code:
    $change = $_POST['change'];
    You might also want to have a look here in the W3Schools PHP tutorial for processing forms.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Practice

    I have 56K....
    ... ....

    Anyways I only have one line in my house. I run Windows XP Home. Is there away I can mess around with php by setting up a virtual server or internet thing on my computer?

  6. #6
    SitePoint Enthusiast ssx-gun's Avatar
    Join Date
    Sep 2002
    Location
    Strongsville, OH
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XP Home can be a bit of an annoyance in this area but for an AMP setup:

    1. httpd.apache.org for an Apache Server
    2. dev.mysql.com/downloads/ for a MySQL Server
    3. www.php.net/downloads.php for the PHP Processor
    PHP: Pills Help People
    ---
    weird-one.com


  7. #7
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or, to have it all in a bundle...

    http://www.apachefriends.org/en/xampp.html
    Lats...

  8. #8
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks for showing me that program its a big help. For one thing there is no dad yelling at me to get off the internet. This is a very simple code I made up:

    <?php
    $name = $_POST['0'];
    $text = fopen(text.txt,a);
    fwrite($text,$name);
    fclose($text);
    ?>

    No I specified to write only at the end of the file. It does all of this on one line. How do I make a separate line for each new entry added?

    And what is the best book to teach me about PHP and MySql?

  9. #9
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    North America
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats a good site to learn php?

  10. #10
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    North America
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    other than php.net

  11. #11
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  12. #12
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Still need that questions answered

    The ode I have listed above works. I know how to make the data be placed at the end of the file, but I do not know how to make each new data entry on a new line in the text file.

  13. #13
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    $change 
    $_POST['change'];

    $content "";

    $content .= $change ."\r\n";

    $content .= $somethingelse ."\r\n";


    $tempfilename 'filename.ext';
    $file fopen($tempfilename'a'); // made change here
    if(!$file) {
        die(
    "Unable to create temp file");
    }

    fwrite($file$content);
    fclose($file); 
    I pulled this stuff outta a download.php file i have for generating a text file with data from my Database. I think it should work for what you're talking about. My file is only created one time tho, so i'm not sure if it works for letting you add one line to the file everytime.

    Edit:


    I made a change in the code to switch the 'w' to a 'a'. THe 'w' means that any pre-existing data will be overwritten in your text file. Using 'a' means that new data will be appended onto the end.
    Last edited by Gibb; Nov 22, 2004 at 14:45.

  14. #14
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a quick list of some books I like, Most are begginer / Inter level:

    PHP and MySQL Web Development

    Beggining PHP 5 and MySQL From Novice To Professional

    PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide

    Build Your Own Database Driven Website Using PHP & MySQL

    I have tried all of these books and each one has helped me learn more. Hopefully this list is ob some use to you thebillionaire.

  15. #15
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Definately the best PHP / MySQL book i've ever used, and there are plans for a 2nd edition with some PHP 5 support in early 2005 I hear (from the author himself)

  16. #16
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gibb
    Definately the best PHP / MySQL book i've ever used, and there are plans for a 2nd edition with some PHP 5 support in early 2005 I hear (from the author himself)
    You have read it to then Gibb! Pretty impressive book isn't it.

  17. #17
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Gibb for that code help. I have a question about the code.

    $content .= $change ."\r\n";

    $content .= $somethingelse ."\r\n";

    What do the periods mean?

  18. #18
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And what does die mean after the if condition?

  19. #19
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steven Vant
    Thanks Gibb for that code help. I have a question about the code.

    $content .= $change ."\r\n";

    $content .= $somethingelse ."\r\n";

    What do the periods mean?
    The .= means to join, or add to, the variable.
    Lats...

  20. #20
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steven Vant
    And what does die mean after the if condition?
    die means 'stop'.
    Lats...

  21. #21
    SitePoint Enthusiast JoJoNAloha's Avatar
    Join Date
    Nov 2004
    Location
    Oregon
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, i think i know how to add stuff to txt files, but how can you search for a string within a txt file and then return the string if it is there or even...

    ok, lets say we have a text file like this

    jimbob blah
    billybob yeah


    ok and then if i wanted to search for the text "jimbob" and then have it echo the string and/or the text following it but not the text on other lines.

  22. #22
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya know JoJoNAloha that would be very useful if someone knew how to do that. It would take place of MySql if somthing is just to small for it. Does anyone think you could set up a username and password form if this were possible?

  23. #23
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JoJoNAloha
    yeah, i think i know how to add stuff to txt files, but how can you search for a string within a txt file and then return the string if it is there or even...

    ok, lets say we have a text file like this

    jimbob blah
    billybob yeah


    ok and then if i wanted to search for the text "jimbob" and then have it echo the string and/or the text following it but not the text on other lines.
    When you read through a file, you can grab entire lines using something like this: (this is the code from my upload.php script, but you can use it for other types of files that are already on the server)
    PHP Code:

    $search_string 
    'jimbob';

    $filename $_FILES['uploadedfile']['tmp_name'];

    $fp fopen($filename 'rb'); // rb == read binary

    while(!feof ($fp)) {
        
    $line fgets($fp1024); // gets 1 full line
        // $line = fgetcsv($fp, 1024, "\t"); // gets 1 full line, but breaks it up 
        //into pieces, and puts those pieces into the array $line

        
    if ( strstr $line$search_string) ) {
            echo 
    'Search string found on this line: <br />';
            echo 
    $line .'<br />';
        }

    I'm not too sure about the strstr function, as i've never had to find a string within a string before, but it looks good from the PHP manual.

  24. #24
    SitePoint Member Steven Vant's Avatar
    Join Date
    Nov 2004
    Location
    Here
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rounding

    I was wondering how php dealt with never ending decimal problems.

    ex. 100/3 comes to be 33.33333333...

    My question is how do you round the the nearest whatever in php. I think this is a good thing to know because I have a friend who wants me to make him a simple quiz. I started to think what would happen if I wanted the result to come out to a percent and if there was and odd number of questions like 100/3 which would give me a run-on answer. I tried the math (100/3) in php and it gave me 33.333333333333. Again how can I make this number round out so I can set it up to show none or 2 decimal places?

  25. #25
    PHP Otaku Gibb's Avatar
    Join Date
    Jul 2004
    Location
    Texas
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP Manual
    <?php
    echo round(3.4); // 3
    echo round(3.5); // 4
    echo round(3.6); // 4
    echo round(3.6, 0); // 4
    echo round(1.95583, 2); // 1.96
    echo round(1241757, -3); // 1242000
    echo round(5.045, 2); // 5.05
    echo round(5.055, 2); // 5.06
    ?>
    the PHP Manual is your friend


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
  •