SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 37
  1. #1
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Guestbook script from book, help with errors

    I'm trying out a guestbook/forums script from a book. I know printer errors are common in some books, so I don't know what is wrong with the script. PLease help me.

    index.php
    PHP Code:
    <?php
    include ('include_fns.php');
    session_start();

    if(!isset(
    $_SESSION['expanded']))
    {
        
    $_SESSION['expanded'] = array();
    }

    if (isset (
    $_SESSION['expand']))
    {
        if (
    $_SESSION['expand'] == 'all')
            
    expand_all($_SESSION['expanded']);
        else
            
    $_SESSION['expanded']$_SESSION['expand'] = true//this is line 15
    }

    if (isset (
    $_SESSION['collapse']))
    {
        if (
    $_SESSION['collapse'] == 'all')
            
    $_SESSION['expanded'] = array();
        else
            unset (
    $_SESSION['expanded'][$_SESSION['collapse']]);
    }

    do_html_header('Discussion Posts');

    display_index_toolbar();

    display_tree($_SESSION['expanded']);

    do_html_footer();
    ?>
    When I run the file I get this error:
    Parse error: parse error, unexpected T_VARIABLE in index.php on line 15
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_SESSION['expanded'][$_SESSION['expand']] = true; //this is line 15

    I think that's what it should be.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that fixed that problem.

    Now I have another one:
    Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in treenode_class.php on line 81

    PHP Code:
    <?php
    class treenode
    {
        var 
    $m_postid;
        var 
    $m_title;
        var 
    $m_poster;
        var 
    $m_posted;
        var 
    $m_children;
        var 
    $m_childlist;
        var 
    $m_depth;
        
        function 
    treenode ($postid$title$poster$posted$children$expand$depth$expanded$sublist)
        {
            
    $this->m_postid $postid;
            
    $this->m_title $title;
            
    $this->m_poster $poster;
            
    $this->m_posted $posted;
            
    $this->m_children $children;
            
    $this->m_childlist = array();
            
    $this->m_depth $depth;
            
            if ((
    $sublist||$expand) && $children)
            {
                
    $conn db_connect();
                
                
    $query "select * from header where parent = $postid order by posted";
                
    $result mysql_query($query);
                
                for (
    $count=0$row = @mysql_fetch_array($result); $count++)
                {
                    if (
    $sublist||$expanded $row['postid'] ] == true)
                        
    $expand true;
                    else
                        
    $expand false;
                    
    $this->m_childlist[$count]= new treenode ($row['postid'],$row['title'],
                                                            
    $row['poster'],$row['posted'],
                                                            
    $row['children'], $expand,
                                                            
    $depth+1$expanded$sublist);
                }
            }
        }
        
        function 
    display ($row$sublist false)
        {
            if (
    $this->m_depth>-1)
            {
            echo 
    '<tr><td bgcolor="';
            if (
    $row%2)
                echo 
    '#cccccc">';
            else
                echo 
    '#ffffff">';
            }
                
            for (
    $i 0$i<$this->m_depth$i++)
            {
                echo 
    '<img src="images/spacer.gif" height="22" width="22" alt="" valign="bottom">';
            }
            
            if ( !
    $sublist && $this->m_children && sizeof($this->m_childlist))
            {
                echo 
    '<a href="index.php?collapse=' $this->m_postid.'"><img src="images/minus.gif" valign="bottom"
                                                        height="22" width="22" alt="Collapse Thread" border="0"></a>'
    ;
            }
            else if (!
    $sublist && $this->m_children)
            {
                echo 
    '<a href="index.php?expand=' $this->m_postid.'"><img src="images/plus.gif" valign="bottom"
                                                        height="22" width="22" alt="Expand Thread" border="0"></a>'
    ;
            }
            else
            {
                echo 
    '<img src="images/spacer.gif" height="22" width="22" alt="" valign="bottom">';
            }
            
            echo 
    " <a name = $this->m_postid ><a href = 'view_post.php?postid=$this->m_postid'>$this->m_title -
                    
    $this->m_poster - ".reformat_date($this->m_posted).'</a>';
            echo 
    '</td></tr>';
            
            
    $row++;
        }
        
        
    $num_children sizeof($this->m_childlist); //Line 81
        
    for ($i 0$i<$num_children$i++)
        {
            
    $row $this->m_childlist[$i]->display($row$sublist);
        }
        return 
    $row;
    }
    ?>
    and:
    Fatal error: Call to undefined function: do_html_header() in index.php on line 26
    There are also two errors because of the first one, so those I can ignore.
    The undefind function... is that something that calls for some function in another script? I'm new to this so I'm not completely sure. If it is, I can easily fix that.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  4. #4
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any one?
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.
    Try removing the } on line 79.
    I think that is 'closing' the method display. So the next lines will actually not be inside any method, which they should be.

    HTH

    -Helge

  6. #6
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try it, but it doesn't seem logical to me. doesn't every { have a corresponding } ? Like a closing tag in HTML?

    EDIT:
    I moved the } to the end instead. So now it works (no errors) Now I have to build a missing function it's asking for. *sigh* why don't the book list all the function it creats in an easy table for reference.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by reptilianfeline
    I'll try it, but it doesn't seem logical to me. doesn't every { have a corresponding }
    You are so right, and I'm really sorry. You should, as you've already done, move it to the end of the script.
    I meant move, but somehow i wrote you should remove it. I guesss it was one of the moment of "an error has occured in brain". [img]images/smilies/smile.gif[/img]

    -Helge

  8. #8
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem

    I started up the CD that comes with the book to see what the complete files look like, and there is a lot of things they left out in the book itself. So now I had to fix a couple of other things as well, and got it almost to work. Now the form doesn't seem to work. Might have something to do with the version of PHP. I'll look through post and get and how the different versions are written.

    My version of store_new_post.php
    PHP Code:
    <?php
    include ('include_fns.php');
    if (
    $id store_new_post($_POST))
    {
        include (
    'index.php');
    }
    else
    {
        
    $error true;
        include (
    'new_post.php');
    }
    ?>
    The version from the CD:
    PHP Code:
    <?php
      
    include ('include_fns.php');
      if(
    $id store_new_post($HTTP_POST_VARS))
      {
        include (
    'index.php');
      }
      else
      {
        
    $error true;
        include (
    'new_post.php');
      }

    ?>
    Why doesn't mine work? Or is the non-function-error somewhere else?
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  9. #9
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your PHP version is earlier than 4.1.0 you need to use the $_HTTP_POST_VARS. If it's newer $_POST should work fine.

    -Helge

  10. #10
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then the error must be somewhere else. The form when submitted says I haven't filled in all the fields, but I have, and it can't save the post. Have to do some digging through the different files then.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  11. #11
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that somewhere in new_post.php or output_fns.php there is an error. It might be a variable that is used but has no field to fill in.

    new_post.php
    PHP Code:
    <?php
    include ('include_fns.php');

    $title $_POST['title'];
    $poster $_POST['poster'];
    $message $_POST['message'];

    if (isset(
    $_GET['parent']))
        
    $parent $_GET['parent'];
    else
        
    $parent $_POST['parent'];

    if(!
    $area)
        
    $area 1;
      
      if(!
    $error)
      { 
        if(!
    $parent)
        {
          
    $parent 0;
          if(!
    $title
            
    $title 'New Post';
        }
        else
        {
          
    $title get_post_title($parent);
       
          if(
    strstr($title'Re: ') == false )
            
    $title 'Re: '.$title;
     
          
    $title substr($title020);

          
    $message add_quoting(get_post_message($parent));
        }
      }
    do_html_header($title);

    display_new_post_form($parent$area$title$message$poster);

    if (
    $error)
    {
        echo 
    'Your message was not stored.
             Make sure you have filled in all fields and try again.'
    ;
    }

    do_html_footer();
    ?>
    And the corresponding part on output_fns.php
    PHP Code:
    <?php
    function display_new_post_form($parent 0$area 1$title=''$message=''$poster='')
    {
      global 
    $table_width;
    ?>
      <table cellpadding = 0 cellspacing = 0 border = 0 width = <?php echo $table_width?>>
      <form action = "store_new_post.php?expand=<?php echo $parent;?>#<?php echo $parent;?>
            method = post>
      <tr>
        <td bgcolor = "#cccccc">
          Your Name:
        </td>
        <td bgcolor = "#cccccc"> 
          <input type = text name = poster value = "<?php echo $poster?>
                        size = 20 maxlength = 20></td>
      </tr>
      <tr>
        <td bgcolor = "#cccccc">
          Message Title:
        </td>
        <td bgcolor = "#cccccc">
          <input type = text name = title value = "<?php echo $title?>
                 size = 20 maxlength = 20></td>
      </tr>
      <tr>
        <td colspan = 2 >
          <textarea name = message rows = 10 cols = 55><?php echo stripslashes($message);?></textarea>
        </td>
      </tr>
      <tr>
        <td colspan = 2 align = center bgcolor = "#cccccc">
          <input type = image name = post src = "images/post.gif" 
                 alt = "Post Message" width = 99 height = 39>
        </td>
        <input type = hidden name = parent value = <?php echo $parent;?> >
        <input type = hidden name = area value = <?php echo $area;?> >
      </tr>
      </form>
      </table>
    <?php
    }
    ?>
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  12. #12
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't understood the logic in you scripts... So it's a bit hard to see what is failing.
    Where is the $error variable coming from? And where/how do you validate the input?

    To check what is stored in the $_POST/$_GET array do this
    PHP Code:
    echo '<pre>' print_r($_POST) . '</pre>';
    echo 
    '<pre>' print_r($_GET) . '</pre>'
    -Helge

  13. #13
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I will try that.

    I am using the book PHP and MySQL Webdevelopment 2nd ed. and the script is from chapter 29 and the guestbook/forum script.

    If you go to <edited away> and click "New post" and try to write something, you'll see what I see.
    Last edited by reptilianfeline; Apr 29, 2003 at 03:23.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  14. #14
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe the error is in this function?
    PHP Code:
    function store_new_post($post)
    {
        
    $conn db_connect();
        
        if (!
    filled_out($post))
        {
            return 
    false;
        }
        
    $post clean_all($post);
        
        if (
    $post['parent'] !=0)
        {
            
    $query "select postid from header where postid = '".$post['parent']."'";
            
    $result mysql_query($query);
            if (
    mysql_numrows($result) !=1)
            {
                return 
    false;
            }
        }
        
        
    $query "select header.postid from header, body where 
                header.postid = body.postid and 
                header.parent = "
    .$post['parent']." and
                header.poster = '"
    .$post['poster']."' and
                header.title = '"
    .$post['title']."' and
                header.area = "
    .$post['area']." and
                body.message = '"
    .$post['message']."'";
        
    $result mysql_query($query);
        if (!
    $result)
        {
            return 
    false;
        }
        if (
    mysql_numrows($result)>0)
            return 
    mysql_result($result00);
            
        
    $query "insert into header values
                ('"
    .$post['parent']."',
                '"
    .$post['poster']."',
                '"
    .$post['title']."',
                0,
                now(),
                NULL
                )"
    ;
        
    $result mysql_query($query);
        if (!
    $result)
        {
            return 
    false;
        }
        
        
    $query 'update header set children = 1 where postid = '.$post['parent'];
        
    $result mysql_query($query);
        if (!
    $result)
        {
            return 
    false;
        }
        
        
    $query "select header.postid from header left join body
                on header.postid = body.postid
                where parent = '"
    .$post['parent']."'
                and poster = '"
    .$post['poster']."'
                and title = '"
    .$post['title']."'
                and body.postid is NULL"
    ;
        
    $result mysql_query($query);
        if (!
    $result)
        {
            return 
    false;
        }
        if (
    mysql_numrows($result)>0)
            
    $id mysql_result($result00);
            
        if (
    $id)
        {
            
    $query "insert into body values ($id, '".$post['message']."')";
            
    $result mysql_query($query);
            if (!
    $result)
            {
                return 
    false;
            }
        return 
    $id;
        }

    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  15. #15
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to see why the queries might be failing, add this to all the queries.
    PHP Code:
    $result mysql_query($query) or die(mysql_error()); 
    -Helge

  16. #16
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Let's see what I get. When I tried the POST and GET arrays I got a couple fo items I can't find anywhere in the scripts.
    Array ( [poster] => Sara [title] => Testing [message] => This is a test [parent] => 0 [area] => 1 [post_x] => 58 [post_y] => 25 )
    1
    Array ( [expand] => 0 )
    1
    post_x and post_y are the ones I can't find out where they are comming from
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  17. #17
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the index.php page I get "No database selected". Ouch!! Now I have to find out why.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  18. #18
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the $_POST['post_x'] $_POST['post_y'] is set because you have a image as a submit button. I don't they cause the trouble.

    Quote Originally Posted by reptilianfeline
    On the index.php page I get "No database selected". Ouch!! Now I have to find out why.
    Then you need to select the db [img]images/smilies/wink.gif[/img]

    It seems that you have a db_connect() function. Check out if that function selects the db. The PHP function that does it is mysql_select_db

    -Helge

  19. #19
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found it I had a closer look at the db-connect function set in another file, and did some crossreferensing in my cPanel to get the right order of things. Now I connect properly.

    Next step... error: Column count doesn't match value count at row 1
    Is it the DB or the HTML? I got it when I tried to post a new message. I'll look through the badly written HTML (the CD copy and past parts) to see if there is a colspan somewhere where it shouldn't be.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  20. #20
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's probably a MySQL failure. You're probably trying to insert more/less values than there are columns in your db table.

    -Helge

  21. #21
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah... sounds strange though considering the info in the book. I think I know what it is though. The DB is empty, no posts so far. And the DB wants to know what posts the new post is related to. That's what I think, anyway. I should be able to create new posts when no other posts are in a thread, so it's kind of strange. *sigh* I have to do some more digging.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  22. #22
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I copied the portion about the new post from the CD, and now it works. Must have missed a line or something, or they ommited something in the book.

    So... now I can post and reply, but the expand and collaps buttons don't work. A little irritating, but... of to do some more digging through the filöes and compare them to the CD.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  23. #23
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got parts of it working.

    -Helge

  24. #24
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very and thank you for helping me to get this far. The explanations in the book are a little thin in some places. For a new book it has a lot of things lacking when it comes to writing HTML that follows the standards, and they say it's XHTML-compliant. Bah, humbug... not even close. That's why I wanted to write it from the book instead of copy from the CD. And I thought I would understand the code better as well. I understand better, but it's a lot of cleaning up to do afterwards, and I'm not up to speed on all the inner workings of PHP yet.
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...

  25. #25
    Kitty Lizard reptilianfeline's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere in Cyberspace
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What a silly misstake! Take a look at the first post and index.php. When I got rid of http_session_vars and http_get_vars, I only put in $_SESSION. I forgot $_GET.
    PHP Code:
    <?php
    include ('include_fns.php');
    session_start();

    if(!isset(
    $_SESSION['expanded']))
    {
        
    $_SESSION['expanded'] = array();
    }

    if (isset (
    $_GET['expand']))
    {
        if (
    $_GET['expand'] == 'all')
            
    expand_all($_SESSION['expanded']);
        else
            
    $_SESSION['expanded'][$_GET['expand']] = true;
    }

    if (isset (
    $_GET['collapse']))
    {
        if (
    $_GET['collapse'] == 'all')
            
    $_SESSION['expanded'] = array();
        else
            unset (
    $_SESSION['expanded'][$_GET['collapse']]);
    }

    do_html_header('Discussion Posts');

    display_index_toolbar();

    display_tree($_SESSION['expanded']);

    do_html_footer();
    ?>
    Reptilian Feline
    | www.reptilian-feline.net | Art | Tutorials | Pets | Music |
    Webdesign the hard way...


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
  •