SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Thread: Parse error

  1. #1
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse error

    I'm getting this message:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/consul12/public_html/phpmysql/chapter4/jokelist.php on line 36
    Line 36 is:

    PHP Code:
      echo '<p>' $row['joketext'] . '</p>'
    This is from the Kevin Yank php/MySQL book, and I've been able to successfully run it from the server on my own computer. I'm trying to run it from the server on my webhost. Any ideas where to look to fix this? Oh, the server on my computer was Windows, and the one on LP is Linux, if that makes a difference.
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  2. #2
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would guess that you did not connect to MySQL correctly.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with parse errors, your mistake is often on the lines before the line reported. this is because the parser did not fail until the line reported.

    so look a few lines before line 36.

    if your text editor provides syntax highlighting for php, your mistake will usually be obvious, as often the colors will go haywire around where you made your mistake. if you dont have an editor that offers this, get one now. a good code editior is indispensable. one i recomend is notepad++

  4. #4
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I actually have Notepad2 for that stuff. I'm having a tough time finding the error in there, though.
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  5. #5
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bobber205
    I would guess that you did not connect to MySQL correctly.
    So where would I look to find this out?
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is not a mysql connection error. this is a parse error.

    you can always post a bit more code if your having a tough time. post the code before line 36.

  7. #7
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it matter that the server I'm transferring all of this to is Linux, and the server on my computer at home is Windows? Just kind of grasping at straws here...
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    different versions of php could cause a parse error in only 1 version, although this is not common.

    i dont think you have the same version of the file on the working and non working server.

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Post some more code as clam suggested. It doesn't look like a connection error.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to print the 5 lines above 36 and below 36

  11. #11
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here they are, and thanks to everybody for taking a look at it:

    PHP Code:
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
      exit(
    '<p>Error performing query: ' mysql_error() . '</p>');
    }

    // Display the text of each joke in a paragraph
    while ($row mysql_fetch_array($result)) {
      echo 
    '<p>' $row['joketext'] . '</p>';
    }

    ?>
    </blockquote>
    </body>
    </html> 
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  12. #12
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't look like the error is in there. Try posting the entire file.

  13. #13
    SitePoint Member coastgames's Avatar
    Join Date
    Sep 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i take that same routine snippet and test it it works. The error is further up the script.

    Are you using any echo<<<EOF 's
    It could be that or even an extra } or {
    CDGcommerce
    Project Devlopment, IT

  14. #14
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my guess is you have an unclosed double quote "

    but post more code.

  15. #15
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, here's the whole thing. What's weird is now I'm not connecting to the database at all. I haven't changed anything.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Our List of Jokes</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php

    // Connect to the database server
    $dbcnx = @mysql_connect('localhost' 'username' 'databasename' 'password');
    if (!
    $dbcnx) {
      exit(
    '<p>Unable to connect to the ' .
          
    'database server at this time.</p>');
    }

    // Select the jokes database
    if (!@mysql_select_db('joketable')) {
      exit(
    '<p>Unable to locate the joke ' .
          
    'database at this time.</p>');
    }

    ?>
    <p>Here are all the jokes in our database:</p>
    <blockquote>
    <?php
      
    // Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
      exit(
    '<p>Error performing query: ' mysql_error() . '</p>');
    }

    // Display the text of each joke in a paragraph
    while ($row mysql_fetch_array($result)) {
      echo 
    '<p>' $row['joketext'] . '</p>';
    }

    ?>
    </blockquote>
    </body>
    </html>
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  16. #16
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You typically need a port number after the server name. Mine is
    "localhost:8889".


    That may be way you're not connecting.

  17. #17
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found somebody in our webhost's forums who helped me out, and we got it fixed. Thanks for your help though.
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  18. #18
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what was the issue?

  19. #19
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't have the correct database name at mysql_select_db. This was one of those "d-ohh" moments, that I seem to have a lot of since attempting to learn php/MySQL.
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  20. #20
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ha!

    I was right.

  21. #21
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bobber205
    I would guess that you did not connect to MySQL correctly.
    Yep!!
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com

  22. #22
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that doesnt make any sense if php was reporting a parse error.

    weird...

  23. #23
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher
    that doesnt make any sense if php was reporting a parse error.

    weird...
    yeah ... that error is completely unrelated to the database connection.

  24. #24
    SitePoint Zealot EOBeav's Avatar
    Join Date
    May 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't say I disagree with you guys...All I know is that it's fixed now.
    Another Storm My personal weblog

    Web Design Resources & Reviews Referenced at SitePoint.com


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
  •