Page 1 of 4 123 ... LastLast
Results 1 to 10 of 39

Thread: PHP+file handling+confused???

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP+file handling+confused???

    Hello everyone,
    I am learnt PHP file handling and plain text database manipulation and I am trying to make a authentication system with plain text database(comma seperated values) the thing which is bugging me is that one can create a user but cannot update h(is/er) profile neither can he delete his username. I have been trying to make it work for a long time now and I finally think I cannot do it on my own. I seek for help and any help would be greatly appereciated. Thank you for your time reading this thread.

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Any help here would be greatly appereciated.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You haven't given enough information for anyone to help you.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok. Here is my description. I have three pages: createuser.php, updateprofile.php and deleteuser.php. They all share a common flat file database(not quite flat) which is database.php which looks like this:

    PHP Code:
    <?php exit(); ?>
    #stores users in
    #comma seperated
    #values.
    #format: username,password,email,zip,country
    createuser.php looks something like this:

    PHP Code:
    <html>
    <
    head>
    </
    head>
    <
    body>
    <
    form name="testform" action="testcreate.php" method="POST">
    UserName:<input type="text" name="name">
    Email:<input type="text" name="email">
    Password:<input type="text" name="password">
    Zip:<input type="text" name="zip">
    Country:<input type="text" name="country">
    <
    input type="submit">
    </
    form>
    </
    body>
    </
    html
    It gets to another file testcreate.php which stores the data using post to the file database.php. testcreate.php looks like this:

    PHP Code:
    <?php
    $handle 
    fopen('database.php''a');
    fwrite($handle$_POST['name'].",".$_POST['password'].",".$_POST['email'].",".$_POST['zip'].",".$_POST['country']."\n");
    fclose($handle);
    echo 
    "Please click <a href='login.php'>here</a> to go to the login page."
    ?>
    This stores the data.

    The deleteuser.php looks like this:

    PHP Code:
    #source php.net
    <?
    $key 
    $_POST["username"];
    $fc=file("database.php");
    $f=fopen("database.php","w");
    foreach(
    $fc as $line)
    {
         if (!
    strstr($line,$key))
               
    fputs($f,$line);
    }
    fclose($f);
    ?>
    The $_POST["username"] comes from a page deleteuser.html.

    The problem I am having is I couldn't make a script to edit the profile of the user.

    I need a script(descripted I am learning PHP not copying) which could let the users update their profile in the flat file database.

    I hope I was able to clear my point.
    Thanks.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, you should create a function that loops through the lines, looks for the supplied username, reads in the information to an array (explode() will help you here), constructs a new line from that data and the new data provided, then deletes the old line and inserts the new one.

    It would have been so much easier to write a demo script.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Umm, I hate to admit it Twey but I have not yet studied about the explode() function and I wish you could give me some hints on doing so. I am just a beginner you remember?? I can create a function that loops through the file and looks for the supplied username(it's similar to the delteuser.php isn't it??) but how do I read the information into an array and construct a new line from the data and add the new data provided and delete the old line??

    EDIT: By the way I just realized the explode() contained a link. Going through it.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's why I gave you the link
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yep went through it. Isn't explode() something like split()??

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Similar, but no regex, just a simple seperator string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now how do I do this part??
    Quote Originally Posted by Twey
    reads in the information to an array (explode() will help you here), constructs a new line from that data and the new data provided, then deletes the old line and inserts the new one.

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
  •