Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry parse error -- please help!

    I am getting a parse error on line 119 of the code below and I cant figure out what is wrong! Can anyone help?



    <?PHP
    /*
    News Class

    Retrevies the news information from the database

    class News {

    /*
    Retreives the latest set of news
    if there is a $category variable, the news will only grab that category

    RETURNS: an array (id, date, title, body)
    */
    function get_all_posts() {
    $sql = "SELECT * FROM news WHERE public_post = 1 ORDER BY post_date DESC";
    $this->print_posts($sql);
    }

    function remove_post($delete_id) {
    $sql = "DELETE FROM news WHERE id = $delete_id LIMIT 1";
    @mysql_query($sql);
    }

    function get_category_posts($category_id = 0,$editable = 0) {
    $category_id = intval($category_id);

    if ($category_id < 0 || $category_id > 11) {
    $category_id = 0;
    }
    $sql = "SELECT * FROM news WHERE category_id = $category_id AND public_post = 1 ORDER BY post_date DESC";
    $this->print_posts($sql,$editable);
    }

    function get_user_posts($user_id, $editable) {
    $sql = "SELECT * FROM news WHERE user_id = $user_id ORDER BY post_date DESC";
    $this->print_posts($sql,$editable);
    }

    function get_post_data($id) {
    global $error;

    $sql = "SELECT * FROM news WHERE id = $id";
    $rs = mysql_query($sql);

    if ($rs) {
    return mysql_fetch_assoc($rs);
    }
    else {
    $error->set_error("Unable to get news Post\n<br>".mysql_error(),ERROR);
    return false;
    }
    }

    function print_posts ($sql,$editable = 1) {
    $rs = mysql_query($sql);
    while (@$row = mysql_fetch_assoc($rs)) {
    ?>

    <p style="font-size:11px; font-weight:normal;">
    <?php
    print "<b style='color:gray;'>" . date("m.d.Y",strtotime($row['post_date'])) . "</b><br>";

    if($row['body']) :
    print "<a href='/news.php?id=" . $row['id'] . "'><b>" . strtoupper($row['headline']) ."</b></a><br>";
    else :
    print "<b>" . strtoupper($row['headline']) ."</b><br>";
    endif;

    print stripslashes($row['blurb']);

    print "<br>";

    if ($editable == 1) :
    print "<a href='sponsor_edit_news.php?id=" . $row['id'] . "' class='action_text'>EDIT NEWS ITEM »</a>";
    elseif ($editable == 2) :
    print "<a href='news.php?id=" . $row['id'] . "&category_id=" . $row['category_id'] . "' class='action_text'>EDIT NEWS ITEM »</a><br>";
    print "<a href='news.php?delete_id=" . $row['id'] . "&category_id=" . $row['category_id'] . "' class='action_text' onClick='return confirm(\"Are

    you sure you want to completely remove this news item?\")'>DELETE NEWS ITEM »</a>";
    endif;
    ?>
    </p>



    <table border="0" width="100%">
    <tr><td style="border-top: 1px solid #000;"><span style="font-size:1px;">&nbsp;</span></td></tr>
    </table>

    <?
    }
    }

    function add_news($category_id, $headline, $blurb, $body, $id = 0,$public_post = 1, $user_id = 74) { # 74 is the admin's user_id
    global $error;

    if (strlen($blurb) > 500) {
    $error->set_error("There is a 250 character maximum on blurbs.\n<br>".mysql_error(),ERROR);
    return false;
    }

    if ($id)
    $sql = "UPDATE news SET category_id = '$category_id', headline = '$headline', blurb = '$blurb', body = '$body', public_post =

    '$public_post' WHERE id = $id";
    else {
    $sql = "INSERT INTO news SET user_id = '$user_id', category_id = '$category_id', headline = '$headline', blurb = '$blurb', body =

    '$body', post_date = NOW(), public_post = '$public_post' ";
    }

    $rs = mysql_query($sql);
    $id = mysql_insert_id();

    if ($rs) {
    return true;
    }
    else {
    $error->set_error("Unable Insert News\n<br>".mysql_error(),ERROR);
    return false;
    }
    }

    }
    ?>

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think your problem is on line 103 but I'm not entirely certain since I can't test it as I have no server.

    Anyway, replace this:
    Code:
    	if ($id) 
    	$sql = "UPDATE news SET category_id = '$category_id', headline = '$headline', blurb = '$blurb', body = '$body', public_post =
    	
    	'$public_post' WHERE id = $id";
    		else {
    with this:
    Code:
    	if ($id) {
    	$sql = "UPDATE news SET category_id = '$category_id', headline = '$headline', blurb = '$blurb', body = '$body', public_post =
    	
    	'$public_post' WHERE id = $id";
    		} else {
    Alex

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    After I formatted the code, you have an extra closing curly bracket

    PHP Code:
    <?PHP
    /*
    News Class

    Retrevies the news information from the database

    class News {

    /*
    Retreives the latest set of news
    if there is a $category variable, the news will only grab that category

    RETURNS: an array (id, date, title, body)
    */
    function get_all_posts() {
        
    $sql "SELECT * FROM news WHERE public_post = 1 ORDER BY post_date DESC";
        
    $this->print_posts($sql);
    }

    function 
    remove_post($delete_id) {
        
    $sql "DELETE FROM news WHERE id = $delete_id LIMIT 1";
        @
    mysql_query($sql);
    }

    function 
    get_category_posts($category_id 0,$editable 0) {
        
    $category_id intval($category_id);

        if (
    $category_id || $category_id 11) {
        
    $category_id 0;
        }
        
        
    $sql "SELECT * FROM news WHERE category_id = $category_id AND public_post = 1 ORDER BY post_date DESC";
        
    $this->print_posts($sql,$editable);
    }

    function 
    get_user_posts($user_id$editable) {
        
    $sql "SELECT * FROM news WHERE user_id = $user_id ORDER BY post_date DESC";
        
    $this->print_posts($sql,$editable);
    }

    function 
    get_post_data($id) {

    global 
    $error;

        
    $sql "SELECT * FROM news WHERE id = $id";
        
    $rs mysql_query($sql);

        if (
    $rs) {
            return 
    mysql_fetch_assoc($rs);
        }else{
            
    $error->set_error("Unable to get news Post\n<br>".mysql_error(),ERROR);
            return 
    false;
        }
    }

    function 
    print_posts ($sql,$editable 1) {
        
    $rs mysql_query($sql);
        while (@
    $row mysql_fetch_assoc($rs)) {
    ?>

    <p style="font-size:11px; font-weight:normal;">
    <?php
        
    print "<b style='color:gray;'>" date("m.d.Y",strtotime($row['post_date'])) . "</b><br>";

        if(
    $row['body']) :
            print 
    "<a href='/news.php?id=" $row['id'] . "'><b>" strtoupper($row['headline']) ."</b></a><br>";
        else :
            print 
    "<b>" strtoupper($row['headline']) ."</b><br>";
        endif;

        print 
    stripslashes($row['blurb']);

        print 
    "<br>";

        if (
    $editable == 1) :
            print 
    "<a href='sponsor_edit_news.php?id=" $row['id'] . "' class='action_text'>EDIT NEWS ITEM »</a>";
        elseif (
    $editable == 2) :
            print 
    "<a href='news.php?id=" $row['id'] . "&category_id=" $row['category_id'] . "' class='action_text'>EDIT NEWS ITEM »</a><br>";
            print 
    "<a href='news.php?delete_id=" $row['id'] . "&category_id=" $row['category_id'] . "' class='action_text' onClick='return confirm(\"Are

            you sure you want to completely remove this news item?\")'>DELETE NEWS ITEM »</a>"
    ;
        endif;
    ?>
    </p>



    <table border="0" width="100%">
    <tr><td style="border-top: 1px solid #000;"><span style="font-size:1px;">&nbsp;</span></td></tr>
    </table>

    <?
        
    }
    }

    function 
    add_news($category_id$headline$blurb$body$id 0,$public_post 1$user_id 74) { # 74 is the admin's user_id
    global $error;

        if (
    strlen($blurb) > 500) {
            
    $error->set_error("There is a 250 character maximum on blurbs.\n<br>".mysql_error(),ERROR);
            return 
    false;
        }

        if (
    $id)
            
    $sql "UPDATE news SET category_id = '$category_id', headline = '$headline', blurb = '$blurb', body = '$body', public_post = '$public_post' WHERE id = $id";
        else {
            
    $sql "INSERT INTO news SET user_id = '$user_id', category_id = '$category_id', headline = '$headline', blurb = '$blurb', body = '$body', post_date = NOW(), public_post = '$public_post' ";
        }

        
    $rs mysql_query($sql);
        
    $id mysql_insert_id();

        if (
    $rs) {
            return 
    true;
        }
        else {
            
    $error->set_error("Unable Insert News\n<br>".mysql_error(),ERROR);
            return 
    false;
        }
    }
    ?>
    Removed the last } and seems to look ok to me now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •