Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Member Borior's Avatar
    Join Date
    Jul 2003
    Posts
    30
    Member #
    2253
    Hi, im trying to put info from a form ($date, $ip, $name etc etc) into an xml document that renders the xml as sticky notes (or post-its, as we brits call them ) .... all this does however, is add the contents of the note ($note) ... to the end of the file. How do i get it to insert $note after $myline (<h1>Notes:</h1>)?

    PHP Code:
    $file "notes.xml";
    $myline "<h1>Notes:</h1>";
    $note '
        <note>
            <date>'
    .$date.'</date>
            <by>'
    .$name.'</by>
            <ip>'
    .$ip.'</ip>
            <heading>'
    .$head.'</heading>
            <body>
            '
    .$content.'
            </body>
        </note>
        '
    ;
    echo 
    $note;

    if(
    $fp=fopen($file"r+")) {
        while(
    $line=trim(fgets($fp))) { 
            if(
    $line == $myline) { 
                
                if (
    is_writable($file)) { 
                    if (!
    fputs($fp$note)) {
                        print 
    "Cannot write to file ($file)";
                    } else {
                        print(
    "Success!");
                       }
                } else {
                       print 
    "The file $file is not writable";
                } 
            
            }
        } 

    Thanks in advance

  2.  

  3. #2
    Junior Member IndigoPixel's Avatar
    Join Date
    Jul 2003
    Location
    Brazil
    Posts
    6
    Member #
    2074
    Instead of using $myline, and $note, just use one variable:
    PHP Code:
    $note "<h1>Notes:</h1>";
    //notice the .= on the next line ... 
    //this appends the text to the end of the previous value, instead of replacing it
    $note .= "
        <note>
            <date>
    $date</date>
            <by>
    $name</by>
            <ip>
    $ip</ip>
            <heading>
    $head</heading>
            <body>
    $content</body>
        </note>"

    btw, it's not just brits who use the term sticky note ... I myself (born in the States, raised in Canada) have always called them Post-its ... and had not, until recently heard the term 'sticky note' Either way, I know what you mean ...:cheeky:

  4. #3
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Post-Its is Trademarked here in the USA as well I think,
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Post-Its is Trademarked here in the USA as well I think.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  6. #5
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    You might also look into XML Tree, a PEAR extension for authoring XML with PHP.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  7. #6
    Member Borior's Avatar
    Join Date
    Jul 2003
    Posts
    30
    Member #
    2253
    I may be using this the wrong way ... but the only way i can see that that helps is if i do:
    PHP Code:
    $file "notes.xml";
    $myline "<h1>Notes:</h1>";
    $note $myline;
    $note .= '
        <note>
            <date>'
    .$date.'</date>
            <by>'
    .$name.'</by>
            <ip>'
    .$ip.'</ip>
            <heading>'
    .$head.'</heading>
            <body>
            '
    .$content.'
            </body>
        </note>
        '
    ;
    echo 
    $note;

    if(
    $fp=fopen($file"r+")) {
        while(
    $line=trim(fgets($fp))) { 
            if(
    $line == $myline) { 
                
                if (
    is_writable($file)) { 
                    if (!
    fputs($fp$note)) {
                        print 
    "Cannot write to file ($file)";
                    } else {
                        print(
    "Success!");
                       }
                } else {
                       print 
    "The file $file is not writable";
                } 
            
            }
        } 

    and all that does is append $note to the end of the file, as before. ... HELP!

  8. #7
    Member Borior's Avatar
    Join Date
    Jul 2003
    Posts
    30
    Member #
    2253
    bump ...

  9. #8
    Junior Member IndigoPixel's Avatar
    Join Date
    Jul 2003
    Location
    Brazil
    Posts
    6
    Member #
    2074
    Ummm ... I'm unsure what exactly you're trying to do. Could you give a more detailed description of what you want to accomplish?

  10. #9
    Member Borior's Avatar
    Join Date
    Jul 2003
    Posts
    30
    Member #
    2253
    ok ... xml file looks like this:
    Code:
    <postits>
    	<h1>Notes:</h1>
    <!-- NEW NOTE _SHOULD_ GO HERE -->
    	<note>
    		<date>19.08.03</date>
                  <ip>1.2.3.4</ip>
    		<by>Nick</by>
    		<heading>Uploads</heading>
    		<body>index.php<br />
    		styles.css <b>x2</b><br />
    		functions.php <b>x2</b><br />
    		home.php<br />
    		services.php</body>
    	</note>
    </postits>
    
    <!-- IT ACTUALLY GOES HERE :-/ -->
    OK, ip, heading, by etc etc etc ... are provided by addnote.php, which is as follows:

    PHP Code:
    <?php
    if ($doform == true) {
        include(
    "form.php");
    } else {
    <
    h4>Check that the details are correct</h4>
    <
    strong>Local date is:</strong
    <?
    php echo $date?>
    <br />
    <strong>Your IP is:</strong> 
    <?php echo $ip?>
    <small>
    &mdash; This will be stored with your note for security purposes.
    </small>
    <br /><br />
    <strong>Your name is:</strong> 
    <?php echo $name?>
    <br />
    <strong>Note heading:</strong> 
    <?php echo $head?>
    <br /><br />
    <strong>Content:</strong>
    <br />
    <textarea rows="10" cols="60" readonly="readonly">
    <?php echo $content?>
    </textarea>
    <br />
    <form action="doadd.php" method="post">
    <input type="hidden" name="date" value="<?php echo $date?>" />
    <input type="hidden" name="ip" value="<?php echo $ip?>" />
    <input type="hidden" name="name" value="<?php echo $name?>" />
    <input type="hidden" name="head" value="<?php echo $head?>" />
    <input type="hidden" name="content" value="<?php echo $content?>" />
    <input type="hidden" name="doadd" value="1" />
    <input type="submit" value="OK" />
    <input type="button" value="Go Back" onclick="history.go(-1)" />
    </form>
    <?php
        
    }
    }
    ?>
    and form.php is, well, i'll leave you to guess on that one .. its not hard

    the info is then passed to doadd.php which is like this:



    PHP Code:
    <?php
    $file 
    "notes.xml";
    $myline "<h1>Notes:</h1>";
    $note $myline;
    $note .= '
        <note>
            <date>'
    .$date.'</date>
            <by>'
    .$name.'</by>
            <ip>'
    .$ip.'</ip>
            <heading>'
    .$head.'</heading>
            <body>
            '
    .$content.'
            </body>
        </note>
        '
    ;

    if(
    $fp=fopen($file"r+")) {
        while(
    $line=trim(fgets($fp))) { 
            if(
    $line == $myline) { 
                
                if (
    is_writable($file)) { 
                    if (!
    fputs($fp$note)) {
                        print 
    "<br />Cannot write to file ($file)";
                    } else {
                        print(
    "<br />Success!");
                       }
                } else {
                       print 
    "The file $file is not writable";
                } 
            
            }
        } 
    }

    ?>

  11. #10
    Member Borior's Avatar
    Join Date
    Jul 2003
    Posts
    30
    Member #
    2253
    bump? .. sorry, not trying to be antisocial and annoying ... i just need some help with this. surely there is some way i can replace $myline with $note instead of appending $note to the end of the file :/


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:23 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com