Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 47

Thread: How to post comments to a php page

  1. #11
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    Quote Originally Posted by Benedizione View Post
    Well, guys, I am stumped on all this scripting too. I have been working with all kinds of stuff for hours and have not established anything. *grins*

    I did find this example: http://www.instantsitecomments.com/test.html that I like the way it works and it would be great to do this...just a simple task it seems.

    It's not php but isn't there some kind of simple code I could establish to create the same thing? Something that is much less complicated than databases and code I do not understand?



    Dre
    More than likely, the code behind that example you would find confusing. The only thing I can recommend is taking your time. New concepts can't be instantly absorbed by our brains. If you be persistent and take a tutorial step by step, completing every exercise highlighted, you will understand it in time. It will also be a stepping stone allowing you to move on to more complicated programming techniques and concepts.

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

    Default

    Is it possible to tweak a simple mail program to "post" to a page instead of sending in an email?

    http://www.dynamicdrive.com/style/cs...less-form/P50/

    Dre

  3. #13
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could, but either way you would want to reference what was already mentioned on how to do it. http://www.php-mysql-tutorial.com/ is a good place to start for using php to post and retrieve info to/from a MySQL database. The following pages should be looked at for some sample code on how to do both of these. The other option is to avoid a database and simply post to text files using the commands I referenced earlier in this thread.

    http://www.php-mysql-tutorial.com/mysql-insert-php.php
    http://www.php-mysql-tutorial.com/php-mysql-select.php


    Hope this helps.

    Edit:
    Also, the link that you posted above is just a form and there is no server side action to it.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. The Following User Says Thank You to thetestingsite For This Useful Post:

    Benedizione (02-18-2008)

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

    Default

    It would certainly be better to avoid the database since it is even more difficult for me. How many pages of php would I need to accomplish this task in just php?

    Is this right............I create a php page with php coding which is going to "echo" off of another .txt page which contains the actual html coding of the design and content of the page?

    Am I close to what I need to do? Or am I still way off base?

    That seems to be the way it worked for my menu and to password protect the page but I have been looking over the php material you all showed me and I am still confused about how to coordinate the coding. I keep goofing around with it to see what it does but would like to know if I am even on the right track or not.

    Dre

  6. #15
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    At this point, you would probably want to hard code the html into the php. Here's a little example. This would all be one file.:

    Code:
    <html>
    <head>
    <title>Comments</title>
    </head>
    <body>
    <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>";
    
    
    ?>
    </body>
    </html>
    Here's an example using a mysql database:

    Code:
    <html>
    <head>
    <title>Comments</title>
    </head>
    <body>
    <h1>Comments</h1>
    <?php
    
    $conn = mysql_connect("localhost","user","password");
    mysql_select_db("database_name",$conn);
    
    // get all the rows from the table named 'comments' in the database 'database_name'
    $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 'text'
          echo "<p>".$row['text']."</p>";
    }
    
    ?>
    </body>
    </html>
    I hope that helped you. By the way, reading and writing to a text file isn't all that easy for a beginner. I'd recommend you stick with a database if your host supports it. It's more commonly used, and it's arguably the most simple way to do this.

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

    Benedizione (02-18-2008)

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

    Default

    Thank you, Jack! I will play around with this and see how it goes.

    I have a big medical terminology exam tomorrow so I may have to wait until after my exam to get back to my coding.

    Dre

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

    Default

    here is a script that uses a text file named comments.txt:
    an example form:
    HTML Code:
    <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>
    submit.php (comments.txt must already be created):
    PHP Code:
    <?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);
    }
    ?>
    read.php:
    PHP Code:
    <?php
    $format
    =Array(
    '<table width="100%" align="center" border="0">\n'
    '<tr>\n<td><b>',//beginning tags for the name
    '</b></td>\n',//ending tags for the name
    '<td>',//beginning tags for the comment
    '</td></tr>',//ending tags for the comment
    '</table>'
    );
    $contents=file("comments.txt");
    $formated_comments=$format[0];
    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];
    ?>
    example page (will display the comments):
    Code:
    <html>
    <head>
    </head>
    <body>
    <?php
    include("read.php");
    echo $formated_comments;
    ?>
    </body>
    </html>
    [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.

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

    Benedizione (02-18-2008)

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

    Default

    I am getting this error message. What does this mean? If a database is setup then what is keeping it from connecting? It connected with another program I tried.


    >>
    Warning: mysql_connect(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/b/e/n/benedizione/html/test.php on line 29

    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/content/b/e/n/benedizione/html/test.php on line 30

    Warning: mysql_query(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/b/e/n/benedizione/html/test.php on line 33

    Warning: mysql_query(): A link to the server could not be established in /home/content/b/e/n/benedizione/html/test.php on line 33

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/b/e/n/benedizione/html/test.php on line 36
    <<

    Dre
    Last edited by Benedizione; 02-12-2008 at 03:38 AM. Reason: grammatical error

  12. #19
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Code:
    $conn = mysql_connect("localhost","user","password");
    mysql_select_db("database_name",$conn);
    Change the highlighted portions of the above line to reflect the details for your own setup.
    Also make sure you've created a MySQL table called "comments" (or change the name in the script if you name it something else)

  13. The Following User Says Thank You to Medyman For This Useful Post:

    Benedizione (02-18-2008)

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

    Default

    Yea, I already tried that and I am still having problems.

    However, I am receiving very rude feedback from the tech support of dynamic drive. I may be forced to leave this forum altogether. Maybe they should send me to prison for having used "a font".

    If there is a rule about using "fonts" in this forum then the "font options" need to be removed altogether. This is truly absurd and insulting.

    Thank you all for your help if I do not get an opportunity to say another word. I may need to look elsewhere for script help.

    Dre
    Last edited by Benedizione; 02-12-2008 at 04:55 PM. Reason: grammatical.....want to send me to prison for fixing an error???

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
  •