SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Location
    Home
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More Parse Errors...

    I have looked this file over 5 times now, trying to see what I have done wrong, and I cannot figure out what it is.

    I get this error:
    Parse error: parse error, unexpected $ in /home/httpd/vhosts/samrusch.com/httpdocs/toget/list.php on line 51

    With this code:
    PHP Code:
    <html>
    <head>
    <title>Sam's To Get List!</title>
    </head>
    <body>

    <table width="700" align="center" bgcolor="#CCCCCC" cellpadding="4" cellspacing="1">
        <tr>
            <td align="center" width="600">
                <font face="arial" size="3"><b>Wanted Item</b></font>
            </td>
            <td align="center" width="100">
                <font face="arial" size="3"><b>Item Price</b></font>
            </td>
        </tr>

    <?php

    $dbhost 
    "localhost";
    $dbuser "samtest";
    $dbpass "gohan";
    $dbname "testing";

    mysql_connect($dbhost$dbuser$dbpass) or die (mysql_error());
    mysql_select_db($dbname) or die (mysql_error());
    $insert "INSERT INTO list (entry, price) VALUES ('$entry', '$price')";
    $select "SELECT * FROM list";

    if (
    $_GET['add']) {
        
    mysql_query($insert);
        
    mysql_close();
    } else {
        
    $result mysql_query($select);
        while (
    $r mysql_fetch_array($result)) {
        
        echo 
    '<tr>
            <td align="center" width="600">
                <font face="arial" size="2">$r[entry]</font>
            </td>
            <td align="center" width="100">
                <font face="arial" size="3">$r[price]</font>
            </td>
        </tr>'
    ;

    }

    ?>

    </table>
    </body>
    </html>
    Can someone PLEASE help me with this? Line 51 is the last line in the code.

  2. #2
    SitePoint Addict betrollwin.com's Avatar
    Join Date
    Nov 2005
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hide you account username and password..

  3. #3
    SitePoint Addict
    Join Date
    Nov 2005
    Location
    Germany
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    apart from your parsing error your echo will not work as expected. Within single quotes variables will not be substituted, because the content won't be parsed ("\n" won't work too). Furthermore, even if you use double quotes you cannot access array elements or object properties like this.

    PHP Code:
    $var "b";
    echo 
    "a $var c"// works as expected
    echo 'a $var c'// does not
    $ar[0] = "b";
    $echo "a $ar[0] c"// does not work as expected

    // better use
    $echo "a "$ar[0] ." c";
    // or even better (saves minimal parse time)
    $echo 'a '$ar[0] .' c'
    HTH,
    Christoph

    PS: Parse errors at the end of the script are mostly triggered by missing braces--your else or while block is unclosed.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also take out the ' in the title so we can see the PHP properly..

    You need 2 end braces at the end, as you have a while inside a else block. Try this code:

    PHP Code:
    <html>
    <head>
    <title>Sams To Get List!</title>
    </head>
    <body>

    <table width="700" align="center" bgcolor="#CCCCCC" cellpadding="4" cellspacing="1">
        <tr>
            <td align="center" width="600">
                <font face="arial" size="3"><b>Wanted Item</b></font>
            </td>
            <td align="center" width="100">
                <font face="arial" size="3"><b>Item Price</b></font>
            </td>
        </tr>

    <?php // 17

    $dbhost "localhost";
    $dbuser "samtest";
    $dbpass "gohan";
    $dbname "testing";

    mysql_connect($dbhost$dbuser$dbpass) or die (mysql_error());
    mysql_select_db($dbname) or die (mysql_error());
    $insert "INSERT INTO list (entry, price) VALUES ('$entry', '$price')";
    $select "SELECT * FROM list";

    if (
    $_GET['add']) {
        
    mysql_query($insert); // 30
        
    mysql_close();
    } else {
        
    $result mysql_query($select);
        while (
    $r mysql_fetch_array($result)) {
        
        echo 
    '<tr>
            <td align="center" width="600">
                <font face="arial" size="2">$r[entry]</font>
            </td>
            <td align="center" width="100"> // 40
                <font face="arial" size="3">$r[price]</font>
            </td>
        </tr>'
    ;

    }
    }

    ?>

    </table>
    </body>
    </html>

  5. #5
    SitePoint Addict
    Join Date
    Oct 2005
    Location
    Home
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, thanks guys. I will edit this file a little more to get it where I want it. But, that was just a road block for me really.

    Thanks again.


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
  •