SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Content Management

    I am learning PHP from Kevin Yank's book "Build your own Database driven Website using PHP and MySQL" and have progressed upto Chapter 6 with the help of my friends at SitePoint.
    I am now stuck with the code for the file, authors.php which allows administrators to add new authors and delete and edit existing ones.
    I am giving the body of my code below:

    <body>
    <h1>Manage Authors</h1>
    <p align="center"><a href="newauthor.php">Create New Author</a></p>
    <ul>
    PHP Code:
    <?php
    // Connect to DB server
    $dbcnx mysql_connect("localhost","root");
    if(!
    $dbcnx)
    {
    die(
    '<p>Unable to connect to the ' .
         
    'database servre at this time.</p>');
    }
    // Select the jokes database
    mysql_select_db('jokes');
    // Request the list of all the authors
    $authors = @mysql_query("SELECT ID, Name FROM Authors");
    if (!
    $authors) {
    die(
    '<p>Error performing query: ' mysql_error() .
    '.</p>;
    }
    // Display the name of each author
    while ($author = mysql_fetch_array($authors)) {
    // I am getting an error on the following line
    $id = $author['
    ID']; 
    $name = $author['
    Name'];
    echo('
    <li>' . $name .
    "[<a href='
    editauthor.php?id=$id'>Edit</a>]" .
    "<a href='
    deleteauthor.php?id=$id'>Delete</a>]".
    '
    </li>');
    }
    ?>
    </ul>
    <p align="center"><a href="admin.html">Return to Front Page</a></p>
    </body>

    I am getting an error in the line mentioned above as follows:
    Parse error: parse error, unexpected T_STRING

    Can you please help me to find out where I am going wrong?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    jppp,

    I just checked a database manager I built modeled on Kevin's code. It appears that you have everything the same (except I used double quotes around the ID instead of single but that shouldn't make any difference).

    Try removing the "@" before your mysql_query as it may be that your column name for 'ID' is really 'id' and you've suppressed the error.

    WHOOPS! I see it! You told PHP to "die('" but didn't close the die statement with the "')" (you have the ";" in there). That should do it for you!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast willthiswork's Avatar
    Join Date
    Feb 2003
    Location
    italy
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error you're reporting is typically caused by a line which is not correctly ended with a semicolon (.

    Usually the parser reports the line where the error occured so you should be easily able to find it. Especially if you use any php o text editor.

    Though watching your code seems to be here

    if (!$authors) {
    die(
    '<p>Error performing query: ' . mysql_error
    () .'.</p>;
    }


    it should read:

    die('<p>Error performing query: ' . mysql_error() .'</p>');
    Regards




  4. #4
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to both of you.

    I corrected the silly typing error that I had made and closed the die statement but I continue to get the same error in the line beginning $id = $authors['ID'].

    dklynn, I checked my database. My column is ID and not id as you suspected that it might be.

  5. #5
    SitePoint Enthusiast willthiswork's Avatar
    Join Date
    Feb 2003
    Location
    italy
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try commenting the line

    PHP Code:
     $id $authors['ID']; 
    and you should get the error message anyway because this line looks correct to me.

    Then copy and paste here the error message. It should point out the exact line where it occurs.

    I think you have a type error somewhere with linking strings together or at the termination of some string (semicolumn missing)

  6. #6
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wrote a comment above the line on which I was getting the error. Now surprisingly, the code is working. I really do not know what the problem was.
    Anyway, thanks a lot for your help and suggestions.


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
  •