Page 1 of 1

small news section. how?

Posted: Mon Jan 08, 2007 2:28 pm
by moisea
hello, i would like to learn how to develop a script that allows me to be able to write, update and delete news on one column of my webpage (trhus is not going to be a big section on my website, about three newstitles). i would like to it to show a small description or news title and have the 'read more...' link.
where do i start, please?
do you know a great tutorial for this?
many thanks.

Posted: Mon Jan 08, 2007 2:33 pm
by Kieran Huggins

Posted: Mon Jan 08, 2007 2:34 pm
by Burrito
save the articles in a database. Fetch the articles contents for your main page. trim the articles to the size you want to display on your main page. include a 'read more' link at the bottom of the 'snippet' that is a link to the full article (based on its row number). fetch the article in question and show the whole thing on the article page.

Posted: Tue Jan 09, 2007 9:38 am
by moisea
thanks guys, i'll look into it. great link kieran!!

Posted: Wed Jan 10, 2007 6:34 am
by moisea
hi kieran, i installed the news script you kindly pointed out to me (many thanks again!) but i am experiencing some difficulties in installing it eventhough it seemed straight forward.
http://zulumonkey.org/?id=tutorials&pag ... nt&oid=171
the problem is i am getting the following errors.

Code: Select all

Notice: Use of undefined constant newsuser - assumed 'newsuser' in j:\program files\easyphp1-8\www\news\config.php on line 94
Notice: Undefined index: newsuser in j:\program files\easyphp1-8\www\news\config.php on line 94
Notice: Use of undefined constant newspass - assumed 'newspass' in j:\program files\easyphp1-8\www\news\config.php on line 94
Notice: Undefined index: newspass in j:\program files\easyphp1-8\www\news\config.php on line 94
the only changes i've made are here:

Code: Select all

/* Insert Your MySql Details here then run config.php in your browser, if the page is blank it means its working but if there is writing on it it means that you put in the wrong details */
$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_news");

/* Set Your Timezone in here, eg -2 */
$timezone_local = "0";

/* Comments To Be Displayed Per Page */
$compp = "10";

/* News Posts To Be Displayed On Front Page */
$frontpagelimit = "5";

/* Set the length of the messages you want to display on the front page */
$stripnews = "200";

/* Admin Usernames And Password */
$admins = array(
  		"Kiki " => "johns",
  		
);
i don't get why am i getting those errors. could please help me on this?
many thanks.

Posted: Wed Jan 10, 2007 10:02 am
by feyd
  • Always quote named array indices.
  • use isset() or array_key_exists() to check for the existence of an element before using it.

Posted: Wed Jan 10, 2007 11:28 am
by moisea
thanks feyd, i quoted the named arrays and changed array to
array_key_exists
but i am still getting errors
Parse error: parse error in j:\program files\easyphp1-8\www\news\config.php on line 25
.
i also used isset() and still getting errors.

Code: Select all

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in j:\program files\easyphp1-8\www\news\config.php on line 25

Posted: Wed Jan 10, 2007 11:36 am
by feyd
post the five lines before and after the line number indicated including that line.

Posted: Wed Jan 10, 2007 7:29 pm
by moisea
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


here is the whole config.php

Code: Select all

<?



/* ==================================== START OF EDITABLE VARIABLES ================================ */

/* Insert Your MySql Details here then run config.php in your browser, if the page is blank it means its working but if there is writing on it it means that you put in the wrong details */
$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("news");

/* Set Your Timezone in here, eg -2 */
$timezone_local = "0";

/* Comments To Be Displayed Per Page */
$compp = "10";

/* News Posts To Be Displayed On Front Page */
$frontpagelimit = "5";

/* Set the length of the messages you want to display on the front page */
$stripnews = "200";

/* Admin Usernames And Password */
$admins = array_key_exists(
  		"username" => "password",  [b]this is where the error is: Parse error: parse error in j:\program files\easyphp1-8\www\news\config.php on line 25[/b]
  		
);


/* ============================ END OF EDITABLE VARIABLES ============================== */

/* ============================ DO NOT TOUCH THIS AREA BELOW ============================== */


/* This will return to the current filename to link between forms */
$self = $_SERVER['PHP_SELF'];
$selffull = $_SERVER['REQUEST_URI'];

/* Some settings */
$time = time();
$timezone_offset = date("Z");
$timezone_add = round($timezone_local*60*60);
$time = round($time-$timezone_offset+$timezone_add);
$date = date("d/m/y", $time);
$ip = $REMOTE_ADDR;

function is_member($username) {
global $admins;
if ($admins[$username] != "") {
return true;
}
return false;
}

function loggedin($username, $password) {
global $admins;
if (empty($username) || empty($password)) {
return false;
} if ($admins[$username] == $password) {
return true;
}
return false;
}

function bbcode($message){
    $search = array(
        '#\[B\](.+?)\[\/B\]#is',
        '#\[i\](.+?)\[\/i\]#is',
        '#\[U\](.+?)\[\/U\]#is'
    );
    $replace = array(
        '<strong>$1</strong>',
        '<em>$1</em>',
        '<span style="border-bottom: 1px solid;">$1</span>'
    );
    return preg_replace($search, $replace, $message);
}

function striplink($text) {
	$word = array(
		"http://" => "",
		"www." => "",
	);
	foreach ($word as $bad => $good) {
  	    $text = str_replace($bad, $good, $text);
}
$text1 = strip_tags(addslashes($text));
$text = "http://";
$text .= "$text1";
return $text;
}


if (loggedin($_COOKIE[newsuser], $_COOKIE[newspass])) {
$profile = array();
$profile[username] = $_COOKIE[newsuser];
}

?>
thanks feyd


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 10, 2007 9:54 pm
by feyd
array_key_exists() is a function. It does not work with array creation notation.