Page 5 of 5 FirstFirst ... 345
Results 41 to 46 of 46

Thread: Comments box

  1. #41
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I've recently started using strtotime, it's a lot easier to work with I find.

    http://php.net/manual/en/function.strtotime.php

    PHP Code:
    $ts strtotime('1999-11-40');
    echo 
    date('Y-m-d'$ts); 
    Corrections to my coding/thoughts welcome.

  2. #42
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks Blue Walrus and Jshor. And yes I agree, you should write coding tutorials for a living (but it would be a bit boring don't you think).

  3. #43
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <?php  

     mysql_connect
    ("localhost""root""") or die(mysql_error());  
     
    mysql_select_db("keyboard_test") or die(mysql_error());  
      

     if(isset(
    $_COOKIE['ID_my_site']))  
     {  
         
    $username $_COOKIE['ID_my_site'];  
         
    $pass $_COOKIE['Key_my_site'];  
              
    $check mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());  
         while(
    $info mysql_fetch_array$check ))       
             {  
      

             if (
    $pass != $info['password'])  
                 {             
    header("Location: login.php");  
                 }  
      
          
         else  
                 {  
                    
    $links "link2.php"
                 }  
             }  
             }  
     else  
      

     {              
     
    header("Location: login.php");  
     }  
      







    ?> 

    <?php  


    if (isset ($_POST['submit']))  

        
    $comment mysql_escape_string (trim (nl2br($_POST['comment'])));    


    $date time();
    $cheese =  "<b>$username</b>  <br /><br />   $comment <br /><tr /> ";   




    $sql mysql_query ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']."')");  




         
       
         
        echo 
    '<center>Your comment has been entered successfully!</center>'
        echo 
    '<center><a href="echo time.php"><br />Please click here</a></center>'
             
    }  
         
    else  



    ?> 


    <html> 
    <head> 

    </head> 
    <body> 
    <?php include("$links");  
    echo 
    "Hey ".$username
    ?>   
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> 
    <p><b>COMMENTS</b></p> 
    <?php 
        
    // POST data wasnt entered, so display the comments and comment form  
        // view comments from database 
           
    $sql mysql_query ("SELECT * FROM comments") or die(mysql_error());; 
           while (
    $row mysql_fetch_array ($sql)) { 
           echo 
    $row['comments'].'<br />'





        echo 
    '<br /><br /> 
        <form action="echo time.php" method="post"> 
        Comments:<br /> 
        <textarea name="comment" cols="40" rows="7"></textarea> 
        <input type="submit" value="Submit" name="submit"> 
        </form>'


    ?> 
    <body style="background-color:lightgreen"> 
    </body> 
    </html>
    That's the entire code for the comments box/ member page. I am trying to display their comments like this.


    NAME
    DATE
    COMMENT


    but I'm not sure how to. Any help?

  4. #44
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    PHP Code:
    <?php 
        
    // POST data wasnt entered, so display the comments and comment form  
        // view comments from database 
           
    $sql mysql_query ("SELECT * FROM comments") or die(mysql_error());; 
           while (
    $row mysql_fetch_array ($sql)) { 
           echo 
    $row['name'].'<br />'
           echo 
    $row['comments'].'<br />'





        echo 
    '<br /><br /> 
        <form action="echo time.php" method="post"> 
        Comments:<br /> 
        <textarea name="comment" cols="40" rows="7"></textarea> 
        <input type="submit" value="Submit" name="submit"> 
        </form>'


    ?> 
    <body style="background-color:lightgreen"> 
    </body> 
    </html>
    Although I'm not sure what you named the field that contains 'name' in MySQL.
    - Josh

  5. #45
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You'll need to double line break after the name if you want an empty line.

    Code:
    echo $row['name'].'<br /><br />';
    Corrections to my coding/thoughts welcome.

  6. #46
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    What about the DATE, on the right hand side?
    And I'm pretty sure , with the edited script it's still relying on this code to display the comment.

    PHP Code:
    $date time();
    $cheese =  "<b>$username</b>  <br /><br />   $comment <br /><tr /> ";   




    $sql mysql_query ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']."')"); 
    I because when I removed the $comment from $cheese, the comments stopped displaying.

    So I need to make a new column in the sql database called name and inserted them sepretly?

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
  •