...

View Full Version : parse error -- please help!



brabee1
01-24-2007, 09:50 AM
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;
}
}

}
?>

Alex!
01-24-2007, 09:59 AM
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:

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:

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

Nightfire
01-24-2007, 10:31 AM
After I formatted the code, you have an extra closing curly bracket



<?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;
}
}
?>


Removed the last } and seems to look ok to me now



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum