Results 1 to 3 of 3

Thread: Can't Locate Syntax Error

  1. #1
    Join Date
    Oct 2012
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't Locate Syntax Error

    Dreamweaver is popping a syntax error for line 8 (below), but I'm just starting out and can't figure out what is the issue. The Code:

    PHP Code:
    <?php
    include ('includes/connect.php');

    function 
    getPosts()) {
        
    $query mysql_query("SELECT * From posts") or die (mysql_error());
        while(
    $post mysql_fetch_assoc($query)) {
             echo 
    "<h2>" $post['Title'] . "by" $post['Author'] . "</h2>";
             echo 
    $post['Content'];
        }
    }     
    ?>
    I am following a Youtube tutorial and it looks the same as in the video and it executes in the video (12:23 time frame in video).

    Note: Doing this on a localhost and not a live host.
    Last edited by Kage Kazumi; 10-21-2012 at 09:38 AM.

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Can you tell us what the error is?
    Also, which line is line 8?


    Also, the mysql functions are depricated.
    You can take a look at this thread.
    But a lot of people still use mysql (but mysqli has more features).

  3. #3
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    You've got an extra round bracket, it should be:
    Code:
    <?php
    include ('includes/connect.php');
    
    function getPosts() {
        $query = mysql_query("SELECT * From posts") or die (mysql_error());
        while($post = mysql_fetch_assoc($query)) {
             echo "<h2>" . $post['Title'] . "by" . $post['Author'] . "</h2>";
             echo $post['Content'];
        }
    }     
    ?>
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

Similar Threads

  1. Parse error: syntax error
    By dcr33 in forum PHP
    Replies: 3
    Last Post: 01-01-2012, 01:05 PM
  2. Replies: 1
    Last Post: 01-28-2011, 03:39 AM
  3. Parse error: syntax error, unexpected $end
    By heavensgate15 in forum PHP
    Replies: 2
    Last Post: 02-24-2010, 06:38 AM
  4. Replies: 2
    Last Post: 02-12-2010, 09:53 AM
  5. Replies: 1
    Last Post: 04-26-2008, 11:22 AM

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
  •