Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 47

Thread: How to post comments to a php page

  1. #31
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    please post all of your code
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  2. #32
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Okay, I have 3 pages right now... test.php, submit.php, comments.txt


    Here is what is on my test.php page (I am withholding my database link and pswd). I think that I must have some words/pages mixed up.

    <h1>Comments</h1>
    <?php

    // read comments from the database, a text file, a xml file, whatever

    // loop through comments, and for each one:
    echo "<p>".$comment['text']."</p>";


    ?>




    <?php

    $conn = mysql_connect("database_link","revelation13","password");
    mysql_select_db("revelation13",$conn);

    // get all the rows from the table named 'revelation13' in the database 'revelation13'
    $getCommentsQuery = mysql_query("SELECT * FROM comments");

    // this loops through the results from the query
    while($row = mysql_fetch_array($getCommentsQuery)) {
    // $row will be an associative array of data for a row during each iteration

    // print the data that's in the column 'comments'
    echo "<p>".$row['comments']."</p>";
    }

    ?>


    <form method="post" action="submit.php">
    <p>Name: <input type="text" name="name" /></p>
    <p>Comment:</p>
    <textarea rows="5" cols="40" name="comment"></textarea>
    <p><input type="submit" value="Post Comment" />
    </form>


    <?php
    foreach (file('comments.txt') as $comment) {
    echo $comment.'<br><hr><br>';
    }
    ?>



    Here is what is on my submit.php page:

    <?php
    if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
    $file=fopen("comments.txt","r+");
    $contents=fread($file,filesize("comments.txt")+1);
    $contents=$contents."\n[".$_POST['name']."]".$_POST['comments'];
    fwrite($file,$contents);
    fclose($file);
    }
    ?>



    <?php

    if(isset($_REQUEST['name']) && isset($_REQUEST['comment'])) {

    $conn = mysql_connect("database_link","revelation13","password");
    mysql_select_db("revelation13",$conn);

    mysql_query("INSERT INTO comments (name, comment) VALUES('".mysql_real_escape_string($_REQUEST['name'])."', '".mysql_real_escape_string($_REQUEST['comment'])."' ");

    echo "Thank you, your comment has been submitted.";

    }

    ?>



    <?php
    if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
    $file=fopen("comments.txt","r+");
    $contents=fread($file,filesize("comments.txt")+1);
    $contents=$contents."\n[".$_POST['name']."]".$_POST['comments'];
    fwrite($file,$contents);
    fclose($file);
    header("Location: http://wwww.propheciesofrevelation.org/test.php");
    }
    ?>



    My comments.txt page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title></title>

    </head>

    <form action="submit.php" method="post">
    Name: <input type="text" name="name"><br>
    Comment:<br>
    <textarea name="comments"></textarea>
    <input type="submit" name="submit" value="Send">
    </form>

    </html>

  3. #33
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    I've been thinking about your question of what page I want to return to after submit. I would like for the page to return to the page where the person types in their post, the page where I intend to have other html on the page. I want to be able to see the post immediately after submitting.

    How do I get it to do that?

    Because when I write in the test.php page where comments.txt is now, the page goes only to the submit.php page after clicking on submit.

    Dre

  4. #34
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you might want to look over your code, you're trying to write it to a database and a text file, but the text file looks like it contains html when it shouldn't contain anything but what the php file wrote to it. try going back to page 2 where i give you a script. don't combine it with mysql and read all of the instructions and comments.
    change read.php:
    Code:
    for($a=0;$a<count($contents);$a++) {
        $formated_comments.=preg_replace("^/\[(.*?)\](.*?)/$",$format[1].'$1'.$format[2].$format[3].'$2'.$format[4],$contents[$a]);
    }
    $formated_comments.=$format[0];
    ?>
    with:
    Code:
    for($a=0;$a<count($contents);$a++) {
        $formated_comments.=preg_replace("^/\[(.*?)\](.*?)/$",$format[1].'$1'.$format[2].$format[3].'$2'.$format[4],$contents[$a]);
    }
    $formated_comments.=$format[5];
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  5. #35
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Okay, I re-read everything. I removed the database info from everything again. And, I changed the code in the read.php file. I removed everything from the comments.txt page but it seems like that page is not doing anything. Are the comments supposed to appear on comments.txt?

    Can I place the "example form" on the same page where I want to "echo the comments"?

    I tried that and then I get this error: Warning: preg_replace(): No ending delimiter '^' found in /home/content/b/e/n/benedizione/html/read.php on line 30

    Dre

  6. #36
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Here is the working, customizable code. It will create comments.txt so you don't have to. The table's class is comments, the td's class that contains the name is name, and the td's class that contains the comment is text.
    Last edited by Master_script_maker; 02-25-2008 at 08:58 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  7. The Following User Says Thank You to Master_script_maker For This Useful Post:

    Benedizione (02-26-2008)

  8. #37
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

        <head>
            <title></title>
            <meta http-equiv="content-type" 
                content="text/html;charset=utf-8" />
            <meta http-equiv="Content-Style-Type" content="text/css" />
        </head>
        <body>
            <div id="container">
                <p><a href="..">Back to Tests</a></p>
                <p>
                    If you submit a piece of text, this page will modify itself.<br />
                </p>
    <!-- COMMENTS START -->

    <!-- COMMENTS END -->
                <form method="post" action="write.php">
                    <textarea name="content" cols="20" rows="6">Test 1234</textarea>
                    <input type="submit" value="Submit" />
                </form>
            </div>
        </body>
    </html>
    PHP Code:
    <?php
        
    if(isset($_POST["content"])) {
            
    $content $_POST["content"];
            
    $content strip_tags($content);
            
    $fc file_get_contents("index.php");
            
    $seek "<!-- COMMENTS START -->";
            
    $start stripos($fc,$seek)+strlen($seek)+1;
            
    $split explode($seek,$fc);
            
    $split[0] .= "\n<p>" $content."</p>";
            
    $split implode($seek,$split);
            
    $h fopen("index.php","w+");
            
    fwrite($h,$split);
            
    fclose($h);
            
    Header("Location: index.php");
        }
    ?>

  9. #38
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Master_script_maker View Post
    Here is the working, customizable code. It will create comments.txt so you don't have to. The table's class is comments, the td's class that contains the name is name, and the td's class that contains the comment is text.
    After I click on "send" the "submit.php" page comes up and says "page not found". Then when I "refresh" the page, the page comes up blank. How do I get the page to go back to the form.php page after clicking on "send"?

  10. #39
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Leafy View Post
    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

        <head>
            <title></title>
            <meta http-equiv="content-type" 
                content="text/html;charset=utf-8" />
            <meta http-equiv="Content-Style-Type" content="text/css" />
        </head>
        <body>
            <div id="container">
                <p><a href="..">Back to Tests</a></p>
                <p>
                    If you submit a piece of text, this page will modify itself.<br />
                </p>
    <!-- COMMENTS START -->

    <!-- COMMENTS END -->
                <form method="post" action="write.php">
                    <textarea name="content" cols="20" rows="6">Test 1234</textarea>
                    <input type="submit" value="Submit" />
                </form>
            </div>
        </body>
    </html>
    PHP Code:
    <?php
        
    if(isset($_POST["content"])) {
            
    $content $_POST["content"];
            
    $content strip_tags($content);
            
    $fc file_get_contents("index.php");
            
    $seek "<!-- COMMENTS START -->";
            
    $start stripos($fc,$seek)+strlen($seek)+1;
            
    $split explode($seek,$fc);
            
    $split[0] .= "\n<p>" $content."</p>";
            
    $split implode($seek,$split);
            
    $h fopen("index.php","w+");
            
    fwrite($h,$split);
            
    fclose($h);
            
    Header("Location: index.php");
        }
    ?>
    How would I use this code?

    It looks like it would place the comments on the same page as does the other code given to me, but also send me back to the same page instead of to a submit.php page?

  11. #40
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Master_script_maker View Post
    Here is the working, customizable code. It will create comments.txt so you don't have to. The table's class is comments, the td's class that contains the name is name, and the td's class that contains the comment is text.
    Do I need to type in "propheciesofrevelation.org" where it says "localhost"? Or do I just leave that?


    <?php
    if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
    if(!is_file("comments.txt")) {
    $write=fopen("comments.txt","x+");
    fclose($write);
    }
    $file=fopen("comments.txt","r+");
    $contents=fread($file,filesize("comments.txt")+1);
    $contents=$contents."\n[".$_POST['name']."]".$_POST['comments'].";";
    fwrite($file,$contents);
    fclose($file);
    header("Location: http://localhost/comment/form.php");
    }
    ?>

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
  •