Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 46

Thread: Comments box

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

    Default

    You need to end the statement

    PHP Code:
    $sql mysql_query ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']"')"
    order the comments by the date descending

    order by date desc
    I'd need to see the html output to tell you what is wrong with the bold username.
    Corrections to my coding/thoughts welcome.

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

    Default

    Somewhere on this page its coming up with this error

    ( ! ) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\echo time.php on line 59


    PHP Code:
    <?php 

     mysql_connect
    ("localhost""****""****") or die(mysql_error()); 
     
    mysql_select_db("****") 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 
                 { 
                   

                 } 
             } 
             } 
     else 
     

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


    $links "link2.php";




    ?>

    <?php 


    if (isset ($_POST['submit'])) 
    {
        
    $comment mysql_escape_string '<b>' trim (nl2br($_POST['comment'])) . '</b>' );  

    $quantity $_POST['quantity'];
    $item $_POST['item'];

    $cheese =  "<b>$username</b>  - $comment  ";  




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


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

        
    else 
    {


    ?>


    <html>
    <head>
    <body style="background-color:lightgreen">
    </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>
    </html>

    I'm pretty sure it's on this line of code
    PHP Code:
    ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']"')"
    But not 100% sure.


    How do I organise the comments by date?




    This is the comments box which is making the entire line bold
    PHP Code:
     
    </body>
     
    </
    html>Hey ----  
    <
    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>
    <
    b>----</b>  - <b>----</b>  <br /><b>----</b>  - <b>----</b>  <br /><b>----</b>  - <b>----</b>  <br /><br /><br />
        <
    form action="member.php" method="post">
        
    Comments:<br />
        <
    textarea name="comment" cols="40" rows="7"></textarea>
        <
    input type="submit" value="Submit" name="submit">
        </
    form></body>
    </
    html

    That's the html output
    Last edited by djr33; 09-19-2012 at 03:48 AM. Reason: user request

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

    Default

    Quote Originally Posted by keyboard1333 View Post
    Somewhere on this page its coming up with this error

    ( ! ) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\echo time.php on line 59


    I'm pretty sure it's on this line of code
    PHP Code:
    ("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']"')"
    But not 100% sure.
    Yes, it is. You didn't close the function with a ")" (I know, it can get confusing sometimes if you have multiple parentheses/brackets/curly brackets).

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

    Quote Originally Posted by keyboard1333 View Post
    How do I organise the comments by date?
    Use the ORDER BY in your SQL selection query. For example:
    Code:
    SELECT * FROM `comments` WHERE id = 1 ORDER BY date DESC
    You can change DESC (descending order) to ASC (ascending order).


    Quote Originally Posted by keyboard1333 View Post
    This is the comments box which is making the entire line bold
    PHP Code:
     
    </body>
     
    </
    html>Hey ----  
    <
    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>
    <
    b>----</b>  - <b>----</b>  <br /><b>----</b>  - <b>----</b>  <br /><b>----</b>  - <b>----</b>  <br /><br /><br />
        <
    form action="member.php" method="post">
        
    Comments:<br />
        <
    textarea name="comment" cols="40" rows="7"></textarea>
        <
    input type="submit" value="Submit" name="submit">
        </
    form></body>
    </
    html

    That's the html output
    You already ended your <body> and <html> tags. Legally, you're not supposed to write any HTML after that. You also did this earlier in your code.

    Try this:
    PHP Code:
    <?php 

     mysql_connect
    ("localhost""****""****") or die(mysql_error()); 
     
    mysql_select_db("****") 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 
                 { 
                   

                 } 
             } 
             } 
     else 
     

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


    $links "link2.php";

    if (isset (
    $_POST['submit'])) 
    {
        
    $comment mysql_escape_string '<b>' trim (nl2br($_POST['comment'])) . '</b>' );  

    $quantity $_POST['quantity'];
    $item $_POST['item'];

    $cheese =  "<b>$username</b>  - $comment  ";  




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


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

        
    else 
    {


    ?>
    <html>
    <head>
    </head>
    <body style="background-color:lightgreen">

    <?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>
    </html>
    Last edited by djr33; 09-19-2012 at 03:49 AM. Reason: user request (content not changed, just removed personal info for keyboard1333)
    - Josh

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

    Default

    Also, not to be picky, but I should mention that you need a doctype. From the looks of it, you're using XHTML standards.

    Add this to the very beginning of your HTML code:
    Code:
    <!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" dir="ltr" lang="en">
    - Josh

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

    Default

    I've got multiple </body> </html> because i'm using php include and the page i'm including has the tags on it. I'll fix that up. Also, thanks for the doctype.

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

    Default

    No problem, and regardless of how many includes you have, your final output should be valid HTML, or you may experience display problems.
    - Josh

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

    Default

    I just changed the bit which is like this
    PHP Code:
        // 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 />'
    to this


    PHP Code:
        // POST data wasnt entered, so display the comments and comment form 
        // view comments from database
           
    $sql mysql_query ("SELECT * FROM `comments` WHERE id = 1 ORDER BY date DESC") or die(mysql_error());;
           while (
    $row mysql_fetch_array ($sql)) {
           echo 
    $row['comments'].'<br />'

    I don't think I did it right because when I ran the edited code the comments didn't show.

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

    Default


    Try this:
    PHP Code:
    <?php 

     mysql_connect
    ("localhost""****""****") or die(mysql_error()); 
     
    mysql_select_db("****") 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 
                 { 
                   

                 } 
             } 
             } 
     else 
     

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


    $links "link2.php";

    if (isset (
    $_POST['submit'])) 
    {
        
    $comment mysql_escape_string '<b>' trim (nl2br($_POST['comment'])) . '</b>' );  

    $quantity $_POST['quantity'];
    $item $_POST['item'];

    $cheese =  "<b>$username</b>  - $comment  ";  




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


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

        
    else 
    {


    ?>
    <html>
    <head>
    </head>
    <body style="background-color:lightgreen">

    <?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>
    </html>
    Just tried it and it ran this error

    ( ! ) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\member.php on line 51

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

    Default

    The comment is now not displaying in bold while their name is, so that's all working. However, now the comments are not displaing with a line inbetween each. I think I might have accidentally changed something. Here is the full code.

    PHP Code:
    <?php  

     mysql_connect
    ("localhost""****""****") or die(mysql_error());  
     
    mysql_select_db("****") 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'])));  
       

    $quantity $_POST['quantity']; 
    $item $_POST['item']; 

    $cheese =  "<b>$username</b>  - $comment  ";   




    $sql mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$cheese."')");  


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



    ?> 


    <html> 
    <head> 
    <body style="background-color:lightgreen"> 
    </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="member.php" method="post"> 
        Comments:<br /> 
        <textarea name="comment" cols="40" rows="7"></textarea> 
        <input type="submit" value="Submit" name="submit"> 
        </form>'


    ?> 
    </body> 
    </html>


    I also have a question. When you use php echo to write something on the page the rest of the page dissapears like in this bit of code

    PHP Code:
        echo '<center>Your comment has been entered successfully!</center>'
        echo 
    '<center><a href="member.php"><br />Please click here</a></center>'
    What I was wondering, is their a way to keep the background light green while still replacing all of the old content?

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

    Default

    Quote Originally Posted by keyboard1333 View Post
    Just tried it and it ran this error

    ( ! ) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\member.php on line 51
    You didn't modify the code with the piece I gave you, which is why you're still receiving that syntax error.

    Use this:
    PHP Code:
    mysql_query("INSERT INTO comments (id,comments,date,ip) VALUES ('0','".$cheese."','".$date."','" $_SERVER['REMOTE_ADDR']"')"); 
    However, now the comments are not displaing with a line inbetween each. I think I might have accidentally changed something
    I didn't find any code that formats the output of the comments... only the comments that were input into the database.

    This should work for separating spaces though:
    PHP Code:
    // 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 
    str_replace("\n""<br />"$row['comments']).'<br />'

    I also have a question. When you use php echo to write something on the page the rest of the page dissapears like in this bit of code
    What disappears?

    What I was wondering, is their a way to keep the background light green while still replacing all of the old content?
    The reason that your background is no longer light green is because you defined that in the <body> tag, which you closed. Then you opened a new <body> tag with no background definition. You cannot have multiple <body>, <head> or <html> tags. Also, <body> cannot be in the <head> tags.

    Try replacing this:
    Code:
    <html> 
    <head> 
    <body style="background-color:lightgreen"> 
    </head> 
    <body>
    With this:
    Code:
    <html> 
    <head> 
    </head>
    
    <body style="background-color:lightgreen">
    Hope this helps.
    Last edited by JShor; 08-06-2011 at 11:06 PM.
    - Josh

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
  •