Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: php submit need

  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php submit need

    I am making a site and its almost done.

    I need a textbox and submitt next to it. What erver somone puts in the box and clicks submitt goes to a html file on the server. And every time something else is added via the text box it takes a new line and i have a collection of data users have said.

    After it happens i need it to take them to a page on the server.

    If you can when the data is on the page there will be a delete on next to it so i can delete them without editing. THERE must be a new line.

    Thanks,

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,039
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php
    if (!isset($_POST['add'])){
    ?>
    <form name="test" action="add.php" method="post">
    <textarea name="add" rows="10" cols="30"> Here is an example </textarea>
    <input type="submit" name="submit" value="submit" />
    </form>
    <?php
    }else{
    $text $_POST['add'];
    $f your.txt;
    $h fopen($fr);
    $contents fread($handlefilesize($filename));
    $contents '' .$text.'<BR/>'.$contents
    $a fwrite($h$content)
    if (
    $a){
    header("Location: http://www.site.com/somedir/page.php");
    }else{
    echo 
    "error";
    }
    }
    and get the contents of your.txt and echo it out into page.php

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it wont work.

    Is that all the code?

  • #4
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Try this

    PHP Code:
    <form action="" method="post">
    Title:
    <br />
    <input type="text" name="title" size="53">
    <br />
    Text:
    <br />
    <textarea name="text" rows="20" cols="40"></textarea><br />
    <br />
    <input type="submit" value="Save">
    </form>
    <?php

    if (@$_POST['title']=="" || @$_POST['text']==""){
        echo 
    "Enter text to save!";
    }
    else {
        
    //this is path to file
        
    $filename './postit.html';
        
    //i used $title to strip HTML/PHP tags < >, and added <h2> HTML tag to decorate title
        
    $title "<h2>".strip_tags($_POST['title'])."</h2>\n";
        
    //with this $_POST['text'] is stripped from html/php tags like title, but also preg_replace 
        //is used to replace \n(every enter that u hit when writing tekst),
        //and instead of that added <p> tags which decorate your new paragraph
        
    $tekstmanage preg_replace('/\n/','</p><p>'strip_tags($_POST['text']));
        
        
    //i should probably write a whole preg_replace function instead, which i will probably later, 
        //but this $tekst variable is used to add finishing and closing tags
        //to our tekst manage. you can see how preg_replace adds first closing than starting tags
        //and with this we just simply add starting before closing and closing after starting tags :confused: ;)
        
    $tekst "<p>".$tekstmanage."</p>\n";
        
        
    //after our variables are defined, we combine them in unique variable which we'll write to file
        
    $content $title.$tekst;
        
        
    //This below is basic write to file function that i found on php.net, and rearanged
        //i'll just explain it briefly
        //
        //this checks weather our filename is writeable (on unix systems like here on trap17)
        //you need to change permissions to the file that allows writing to world 646
        
    if (is_writeable($filename)){
        
            
    //if file cant be opened to add -> 'a' <- in the fopen construct
            //just echo sorry
            
    if(!$handlefopen($filename,'a')){
                echo 
    "Sorry, you can't write to file1";
            }
            
    //if file cant be written to, same
            
    if (fwrite($handle$content) === FALSE){
                echo 
    "Sorry, you can't write to file2";
                exit;
            }
        
    //if both of those terms are fine just echo the confirmation text
        
    echo "You wrote to file ".$filename."<br />";
        echo 
    "<a href=\"postit.html\">View</a>";
        
        }
        else {
        echo 
    "Sorry, you can't write to file3";
        }
    }

    ?>
    Be sure to have postit.html in the same directory

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,039
    Thanks
    19
    Thanked 42 Times in 42 Posts
    no it wasnt the full code, it was example code, do you want somebody to do work for you for free?

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://krissyafc.110mb.com/reg/reg.php

    I only want a small code...

    http://krissyafc.110mb.com/reg/reg.php it wont work

    What i need is a script that users can put the email in then it will go to a html for each email and take a new line on each new email added. No SQL.

    Then it will take them to another page.

  • #7
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    u'r missing something in my code.. < at the begening..

    btw, the logic is in the code, weather it to be a title or, email, or bunch of other things, just add them in form, and PHP part.

    Like rafiki said, users here will help you, but won't do the job for you...

  • #8
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I get: Unable to write file 3?

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,039
    Thanks
    19
    Thanked 42 Times in 42 Posts
    chmod it to 0755
    http://uk2.php.net/chmod

  • #10
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still the same.

    All it is is a sign up to our mailing list thing then I ceck it every day and add new ones to the list.

  • #11
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,039
    Thanks
    19
    Thanked 42 Times in 42 Posts
    does the file exist and is it in the correct folder, ./postit.html the dot/period makes it go UP a directory

  • #12
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by krissyafc View Post
    I get: Unable to write file 3?
    filename isn't writable. chmod file to 777. if you don't know how to chmod..

  • #13
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,039
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by matak View Post
    filename isn't writable. chmod file to 777. if you don't know how to chmod..
    according to php.net/chmod you should use 0777 (octal value) and should set it to 0755 for Everything for owner, read and execute for others


  •  

    Posting Permissions

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