Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Any help with guestbook?

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default Any help with guestbook?

    I have problems with information which i want to receive...
    It must show messages posted before, but it doesnt.
    Can you tell me whats wrong??

    PHP Code:
    <?php

    echo "<h1>Guestbook</h1><hr>";

    //connect to the database
    $connect mysql_connect("server","aur","king") or die("Error connecting to db");
    //select table
    mysql_select_db("phpacademy") or die("Error selecting db");

    //use query to get ALL data
    $queryget mysql_query("SELECT * FROM guestbook") or die("Error with query");

    while (
    $row mysql_fetch_assoc($querryget))
    {
        
    // get row data and store in variables
        
    $id $row['id'];
        
    $name $row['name'];
        
    $email $row['email'];
        
    $message $row['message'];
        
    $date $row['date'];
        
    $time $row['time'];
        
        
    // show data to user
        
    echo "
        <table>
            <tr>
                <td>
                <b>Posted by 
    $name ($email) on $date and $time</b> 
                </td>
            </tr>
            <tr>
                    <td>
                    "
    .n12br(strip_tags($message))."
                    </td>
            </tr>
        </table>
        "
    ;    
    }

    echo 
    "<hr>";

    if (
    $_POST['submit'])
    {
      
      
    $name $_POST['name'];
      
    $email $_POST['email'];
      
    $message $_POST['message'];
      
    $date date("Y-m-d");
      
    $time date("H:i:s");
      
      if (
    $name&&$email&&$message)
      {
      
      
    $querypost mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
      echo 
    "Please wait...<meta http-equiv='refresh' content='2'>";
     
      }
      else
        echo 
    "Please fill out all fields!";


    }

    echo 
    "
    <form action='guestbook.php' method='POST'>
    <table width='100%'>
            <tr>
                <td width='17%' valign='top'>
                Your name:
                </td>
                <td>
                <input type='text' name='name' maxlenght='25'>
                </td>
            </tr>
            
            <tr>
                <td  valign='top'>
                Your email:
                </td>
                <td>
                <input type='text' name='email' maxlenght='35'>
                </td>
            </tr>
            
            <tr>
                <td valign='top'>
                Your message:
                </td>
                <td>
                <textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
                <p>
                <input type='submit' value='Post'>
                </td>
            </tr>
    </table>
    </form>
    "
    ;

    ?>
    login and pass changed

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

    Default

    I've never used that n12br but a google says its nl not 1 nl2br(); so try this out. I fiddled with the formatting of some things to you can swap that if you dont link but i think you'll end up with a lot of tables the way you had it


    PHP Code:


    <h1>Guestbook</h1><hr>
    <?php
    //connect to the database
    $connect mysql_connect("server","aur","king") or die("Error connecting to db");
    //select table
    mysql_select_db("phpacademy") or die("Error selecting db");

    //use query to get ALL data
    $queryget mysql_query("SELECT * FROM guestbook") or die("Error with query");
    ?>
        <table>
            <tr>
    <td><strong>Posted by</strong><td><strong>On</strong></td><td><strong>Message</strong></td></tr> 
    <?php

    while ($row mysql_fetch_assoc($querryget))
    {
        
    // get row data and store in variables
        
    $id $row['id'];
        
    $name $row['name'];
        
    $email $row['email'];
        
    $message $row['message'];
        
    $date $row['date'];
        
    $time $row['time'];
        
        
    // show data to user
    ?>
    <tr>
    <td><?php echo $name "(" $email .")"?></td>
    <td><?php echo $date?><?php echo $time?></td>
    <td><?php nl2br(strip_tags($message)); ?></td>       
    </tr>
    <?php        
    }
    ?>
    </table>
    <hr>
    <?php
    if ($_POST['submit'])
    {
      
      
    $name $_POST['name'];
      
    $email $_POST['email'];
      
    $message $_POST['message'];
      
    $date date("Y-m-d");
      
    $time date("H:i:s");
      
      if (
    $name&&$email&&$message)
      {
      
      
    $querypost mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
      echo 
    "Please wait...<meta http-equiv='refresh' content='2'>";
     
      }
      else
        echo 
    "Please fill out all fields!";


    }
    ?> 
    <form action='guestbook.php' method='POST'>
    <table width='100%'>
            <tr>
                <td width='17%' valign='top'>
                Your name:
                </td>
                <td>
                <input type='text' name='name' maxlenght='25'>
                </td>
            </tr>
            
            <tr>
                <td  valign='top'>
                Your email:
                </td>
                <td>
                <input type='text' name='email' maxlenght='35'>
                </td>
            </tr>
            
            <tr>
                <td valign='top'>
                Your message:
                </td>
                <td>
                <textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
                <p>
                <input type='submit' value='Post'>
                </td>
            </tr>
    </table>
    </form>

  3. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    But this line just apears between two lines... nothing changed. I still cant see my messages.

    PHP Code:
     <table
            <
    tr
    <
    td><strong>Posted by</strong><td><strong>On</strong></td><td><strong>Message</strong></td></tr

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

    Default

    Opps my mistake forgot to close a cell

    <td><strong>Posted by</strong></td>
    <td><strong>On</strong></td>
    <td><strong>Message</strong></td></tr>

    What does it display nothing this with blank info or an error? Is there a link?

  5. #5
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    Opps my mistake forgot to close a cell

    <td><strong>Posted by</strong></td>
    <td><strong>On</strong></td>
    <td><strong>Message</strong></td></tr>

    What does it display nothing this with blank info or an error? Is there a link?
    it desplays a line of words: Posted by On Message... but i need a message from mySQL.
    Last edited by auriaks; 08-09-2009 at 11:20 AM.

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

    Default

    You misspelled the variable $querryget. Your calling var is named $queryget with 1 "r" and the other is $querryget w/2 "r"s.

    Additionally, mysql_fetch_assoc(); will only return a specified row. Since none is specified, use mysql_fetch_array(); instead.

    PHP Code:
    <?php 

    echo "<h1>Guestbook</h1><hr>"

    //connect to the database 
    $connect mysql_connect("server","aur","king") or die("Error connecting to db"); 
    //select table 
    mysql_select_db("phpacademy") or die("Error selecting db"); 

    //use query to get ALL data 
    $queryget mysql_query("SELECT * FROM guestbook") or die("Error with query"); 

    while (
    $row mysql_fetch_array($queryget)) 

        
    // get row data and store in variables 
        
    $id $row['id']; 
        
    $name $row['name']; 
        
    $email $row['email']; 
        
    $message $row['message']; 
        
    $date $row['date']; 
        
    $time $row['time']; 
         
        
    // show data to user 
        
    echo 
        <table> 
            <tr> 
                <td> 
                <b>Posted by 
    $name ($email) on $date and $time</b>  
                </td> 
            </tr> 
            <tr> 
                    <td> 
                    "
    .n12br(strip_tags($message)).
                    </td> 
            </tr> 
        </table> 
        "
    ;     


    echo 
    "<hr>"

    if (
    $_POST['submit']) 

       
      
    $name $_POST['name']; 
      
    $email $_POST['email']; 
      
    $message $_POST['message']; 
      
    $date date("Y-m-d"); 
      
    $time date("H:i:s"); 
       
      if (
    $name&&$email&&$message
      { 
       
      
    $querypost mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')"); 
      echo 
    "Please wait...<meta http-equiv='refresh' content='2'>"
      
      } 
      else 
        echo 
    "Please fill out all fields!"




    echo 

    <form action='guestbook.php' method='POST'> 
    <table width='100%'> 
            <tr> 
                <td width='17%' valign='top'> 
                Your name: 
                </td> 
                <td> 
                <input type='text' name='name' maxlenght='25'> 
                </td> 
            </tr> 
             
            <tr> 
                <td  valign='top'> 
                Your email: 
                </td> 
                <td> 
                <input type='text' name='email' maxlenght='35'> 
                </td> 
            </tr> 
             
            <tr> 
                <td valign='top'> 
                Your message: 
                </td> 
                <td> 
                <textarea cols='20' rows='2' name='message' maxlenght='250'></textarea> 
                <p> 
                <input type='submit' value='Post'> 
                </td> 
            </tr> 
    </table> 
    </form> 
    "


    ?>
    HTH
    - Josh

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

    auriaks (08-10-2009)

  8. #7
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    JShor, now i can see my msges thanks to you... but still one problem, i cant add posts.
    Last edited by auriaks; 08-10-2009 at 01:43 AM.

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

    Default

    $_POST['submit'] wasn't declared in your button function. So the if..else statement becomes invalidated, which means the SQL query won't run. You need to add the name="submit". Here's the fixed code:

    PHP Code:
    <?php 

    echo "<h1>Guestbook</h1><hr>"

    //connect to the database 
    $connect mysql_connect("server","aur","king") or die("Error connecting to db"); 
    //select table 
    mysql_select_db("phpacademy") or die("Error selecting db"); 

    //use query to get ALL data 
    $queryget mysql_query("SELECT * FROM guestbook") or die("Error with query"); 

    while (
    $row mysql_fetch_array($queryget)) 

        
    // get row data and store in variables 
        
    $id $row['id']; 
        
    $name $row['name']; 
        
    $email $row['email']; 
        
    $message $row['message']; 
        
    $date $row['date']; 
        
    $time $row['time']; 
         
        
    // show data to user 
        
    echo 
        <table> 
            <tr> 
                <td> 
                <b>Posted by 
    $name ($email) on $date and $time</b>  
                </td> 
            </tr> 
            <tr> 
                    <td> 
                    "
    .n12br(strip_tags($message)).
                    </td> 
            </tr> 
        </table> 
        "
    ;     


    echo 
    "<hr>"

    if (
    $_POST['submit']) 

       
      
    $name $_POST['name']; 
      
    $email $_POST['email']; 
      
    $message $_POST['message']; 
      
    $date date("Y-m-d"); 
      
    $time date("H:i:s"); 
       
      if (
    $name&&$email&&$message
      { 
       
      
    $querypost mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')"); 
      echo 
    "Please wait...<meta http-equiv='refresh' content='2'>"
      
      } 
      else 
        echo 
    "Please fill out all fields!"




    echo 

    <form action='guestbook.php' method='POST'> 
    <table width='100%'> 
            <tr> 
                <td width='17%' valign='top'> 
                Your name: 
                </td> 
                <td> 
                <input type='text' name='name' maxlenght='25'> 
                </td> 
            </tr> 
             
            <tr> 
                <td  valign='top'> 
                Your email: 
                </td> 
                <td> 
                <input type='text' name='email' maxlenght='35'> 
                </td> 
            </tr> 
             
            <tr> 
                <td valign='top'> 
                Your message: 
                </td> 
                <td> 
                <textarea cols='20' rows='2' name='message' maxlenght='250'></textarea> 
                <p> 
                <input type='submit' value='Post' name='submit'>
                </td> 
            </tr> 
    </table> 
    </form> 
    "


    ?>
    HTH
    - Josh

  10. #9
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    still no changes... no adding. somethin is missing.

  11. #10
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    while my guestbook didnt work, i use another guestbook... but in it isnt LITHUANIAN letters like: ąčęėįšųūž... what i have to do, to correct that? you can download this guestbook here: http://swat.xz.lt/auriaks

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
  •