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

Thread: Comments box

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

    Default

    I think I changed the right bit

    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 
                 { 
                   

                 } 
             } 
             } 
     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><br />   $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>

    but it's still coming up with the same 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 58

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

    Default

    I changed one of the bits of code

    PHP Code:
    $cheese =  "<b>$username</b><br />   $comment  "
    So that it displays their name then on the next line their comment. Like this

    Name
    Their comment
    Name
    Their comment
    Name
    Their comment
    Name
    Their comment

    When I would like it to look like this

    Name
    Their comment

    Name
    Their comment

    Name
    Their comment

    Name
    Their comment


    Any help?

  3. #33
    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
    I think I changed the right bit

    but it's still coming up with the same 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 58
    This time you had a period missing in that same line of code.

    Use this:
    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 
                 { 
                   

                 } 
             } 
             } 
     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><br />   $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>
    - Josh

  4. #34
    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
    I changed one of the bits of code

    PHP Code:
    $cheese =  "<b>$username</b><br />   $comment  "
    So that it displays their name then on the next line their comment. Like this

    Name
    Their comment
    Name
    Their comment
    Name
    Their comment
    Name
    Their comment

    When I would like it to look like this

    Name
    Their comment

    Name
    Their comment

    Name
    Their comment

    Name
    Their comment


    Any help?
    Can't you just add another line-breaker tag?

    PHP Code:
    $cheese =  "<b>$username</b><br /><br />   $comment  "
    That should work for you.
    - Josh

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

    Default

    Yep, that all works now. Thanks for all the help.

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

    Default

    I ran the code and into the date column it inserted this



    2007-08-11

    PHP Code:
    $date date("d/m/y"); 
    That's what it should be inserting but the date is wrong. it should be 08/08/2011.
    Any help?

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

    Default

    What do you mean by inserting? Inserting into MySQL? YYYY-MM-DD is the typical date format for a field that has the type set to DATE.

    If that's the case, try changing it to VARCHAR or TEXT or something. You could also insert the date in UNIX time using BIGINT, which is actually a more elegant solution.
    - Josh

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

    Default

    How do I use unix time?

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

    Default

    http://php.net/time

    UNIX time is the number of seconds since the beginning of the UNIX epoch (January 1st, 1970 at midnight Greenwich time).

    The time() function returns the time in UNIX time. Store that large number in a BIGINT column in MySQL and when you go to fetch the date, you can convert it with the date() function.

    Let's suppose you have the number 1312848370. That is the UNIX time for August 8th, 2011 8:06:24 PM EST. The second argument of the date() function accepts a UNIX timestamp and converts it into a string format.

    For example, the following would return 08/08/11
    PHP Code:
    echo date("d/m/y"1312848370); 
    For more information, see:
    http://php.net/time
    http://php.net/date

    I should write programming tutorials for a living.
    - Josh

  10. #40
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default From what I

    have seen you would be very good at it.

    You explain things quite well

    Bud

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
  •