Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Guestbook problem with data output

    Hi guys,

    I'm having a problem with my guestbook script. It's not displaying data entered into the table, it just outputs names of specific columns.

    In this manner:

    Entries found.

    Posted by name (email) on timestamp:
    message

    Posted by name (email) on timestamp:
    message

    Posted by name (email) on timestamp:
    message


    I'm not getting any error messages and that makes it difficult to understand what is actually wrong with this code. Any ideas what needs to be done? Thanks in advance!

    PHP Code:
    <?php

    if (mysql_connect('localhost','root','password') && mysql_select_db('phpdemo')) {

    $time time();
    $errors = array();

    if (isset(
    $_POST['guestbook_name'], $_POST['guestbook_email'], $_POST['guestbook_message'])) {

    $guestbook_name mysql_real_escape_string(htmlentities$_POST['guestbook_name'])); 
    $guestbook_email mysql_real_escape_string(htmlentities$_POST['guestbook_email'])); 
    $guestbook_message mysql_real_escape_string(htmlentities$_POST['guestbook_message'])); 

    if (empty(
    $guestbook_name) || empty($guestbook_email) || empty($guestbook_message)) {
    $errors[] = 'All fields are required.';
    }

    if (
    strlen($guestbook_name)>25 || strlen($guestbook_email)>50 || strlen($guestbook_message)>250){
       
    $errors[] = 'One or more fields exceeded the character limit!';    
    }

    if (empty(
    $erros)) {
    $insert "INSERT INTO guestbook VALUES ('','$time','$guestbook_name','$guestbook_email','$guestbook_message')";
    if (
    mysql_query($insert)){
    header ('Location: '.$_SERVER['PHP_SELF']);
    } else {
    $errors[] = 'Something went wrong. Try again.';
    }

    } else {
    foreach(
    $errors as $error) {
    echo
    '<p><strong>'.$error.'</strong></p>'
    }

    }

    }
    // display entries 
    $entries mysql_query("SELECT 'timestamp', 'name', 'email', 'message' FROM guestbook ORDER BY 'timestamp' DESC");

    if (
    mysql_num_rows($entries)==0){
    echo 
    'No entries, yet.';
    } else { 
    echo 
    'Entries found.'
     
    while (
    $entries_row mysql_fetch_assoc($entries)){
       
    $entries_timestamp $entries_row['timestamp'];
       
    $entries_name $entries_row['name'];
       
    $entries_email $entries_row['email'];
       
    $entries_message $entries_row['message'];
    echo 
    '<p><strong>Posted by '.$entries_name.' ('.$entries_email.') on '.$entries_timestamp.'</strong>:<br>'.$entries_message.'</p>';

    }
    }

    } else {
      echo 
    'Could not connect at this time.';
    }

    ?>

    <hr>
    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
    <strong>Post something...</strong><br>
    Name:<br><input type="text" name="guestbook_name" maxlength="25"><br>
    Email: <br><input type="text" name="guestbook_email" maxlength="250"><br>
    Comment body: <br><textarea name="guestbook_message" rows="6" cols="30" maxlength="250"></textarea><br>
    <input type="submit" value="Submit comment">
    </form>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Try doing away with the apostrophes:
    mysql_query("SELECT 'timestamp', 'name', 'email', 'message'

    Either use nothing:
    mysql_query("SELECT timestamp, name, email, message

    or use backticks:
    mysql_query("SELECT `timestamp`, `name`, `email`, `message`

    See if that makes any difference.

    Also enable error reporting and check that you have data in the table to display.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    tkm76 (09-17-2011)

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Removing single quotes worked.
    The only problem remaining is the timestamp column.
    I am getting "1315765293" instead readable date.

    Also, how would you suggest i replace the "isset" line to suit IE?
    I'm using IE8 at the moment and everything seems to be working pretty much the same as in FF.

    Many thanks!

    tkm

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by tkm76 View Post
    I am getting "1315765293" instead readable date.

    Also, how would you suggest i replace the "isset" line to suit IE?
    1) Lookup the date() function. Input your desired effect and pass the timestamp into it as the second parameter.

    2) isset() is nothing to do with IE. It's a php function which runs on the server. If you're having a problem with your page layout thats better suited to the html/css forums. isset() is used to test that a variable is set.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •