• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Znote AAC] More (advanced) news sytem

Raggaer

Godly Member
Joined
Jul 25, 2012
Messages
1,557
Solutions
8
Reaction score
957
Location
Spain
Well this is the 1.2 part of my news sytem with delete news and edit news, enjoy,

( no photo this time, I have no time )

- Install -

run this at your mysql database
Code:
CREATE TABLE IF NOT EXISTS `znote_news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) NOT NULL,
  `text` text NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

open your index.php replace all code with this
PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>

<h1>News</h1>
<?php

$getnews = mysql_query("SELECT * FROM `znote_news` ORDER BY `id` DESC LIMIT 3");
while ($parsenews = mysql_fetch_assoc($getnews)) {
	$title = $parsenews['title'];
	$body = $parsenews['text'];
	$date = $parsenews['date'];
	echo '<table border="0" cellspacing="5"><tr>';
	echo '<td><strong><p>'.$title.'</strong> - posted on <strong>'.$date.'</strong></p></tr></td>';
	echo '<td>'.$body.'</td></tr></table>';
}
?>
<?php
include 'layout/overall/footer.php'; ?>

create a new php document called addnews and paste this

PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>
<?PHP
protect_page();
admin_only($user_data);
echo '<center><b>News panel</b></center><br>';
$action = $_GET['action'];
$edit = $_GET['edit'];
if ($action == '' && $edit == '') {

$getnews = mysql_query("SELECT * FROM `znote_news` ORDER BY `id` DESC LIMIT 6");
echo '<table><tr class="yellow"><td><center>
<form action="addnews.php?action=add" method="post">
<input type="submit" name="submit" value=" Add news "></form>
<form action="" method="get">
<input type="submit" name="" value=" Edit selected news ">
<br>
<br>';
while ($news = mysql_fetch_assoc($getnews)) {
	$til = $news['title'];
	$dat = $news['date'];
	$id = $news['id'];
echo '</center><li><b><input type="radio" name="edit" value="'.$id.'"> -> '.$til.'</b> posted on '.$dat. '</li><br>';
}
echo '</form></td></tr></table>';

} else if ($action == 'add') {
echo 'Add news panel :<br>';
echo '<table><tr class="yellow"><td><form action="addnews.php?action=add" method="post">
<input type="text" name="title"> News title </td></tr><tr class="yellow"><td>News body ( you can use PHP tags )<br>
<textarea name="body" rows="30" cols="80" style="resize:none"></textarea><br>
</td></tr><tr><td><center><input type="submit" name="add" value=" Add news "></center></td></tr></table></form>';

if ($_POST['add']) {
	
	$title = mysql_real_escape_string($_POST['title']);
	$body = $_POST['body'];
	$date = date("Y-m-d");

	if ($body && $title) {

	$addnews = mysql_query("INSERT INTO `znote_news` VALUES ('','$title','$body','$date')");
	header("Location: addnews.php");
	
	}


} 

} 

if ($edit >= 1) {
	$loadit = mysql_query("SELECT * FROM `znote_news` WHERE `id` = $edit") or die(mysql_error());
	$parse = mysql_fetch_assoc($loadit);
	echo 'Edit news panel: <br><br>';
	$loadtitle = $parse['title'];
	$loadbody = $parse['text'];
	echo '<form action="" method="post"><input type="text" name="title" value="'.$loadtitle.'"> News title<br><br><textarea name="body" rows="30" cols="80" style="resize:none">'.$loadbody.'</textarea><br><input type="submit" name="submited" value=" Edit news "></form><br><form action="" method="post"><input type="submit" name="del" value=" Delete news "></form>';
	
	if ($_POST['submited']) {
		
		$titulo = $_POST['title'];
		$bodie = $_POST['body'];
		
		mysql_query("UPDATE znote_news SET title= '$titulo', text= '$bodie' WHERE id = $edit") or die(mysql_error());
		header("Location: addnews.php");
			
	} else if($_POST['del']) {
		
		
		mysql_query("DELETE FROM `znote_news` WHERE `id` = $edit");
		header("Location: addnews.php");
	}
	
	
}

?>
<?php
include 'layout/overall/footer.php'; ?>

open \layout\widgets\loggedin.php and change code to this

PHP:
<li>
     <a href='admin.php'>Admin Page</a>
     <a href='addnews.php'>Admin Add News</a>
</li>

thanks,
 
Great! Rep++

- - - Updated - - -

Still having some errors when I want to add news. It doesnt stop the posting though.

Code:
Notice: Undefined index: action in C:\xampp\htdocs\tibia\addnews.php on line 7

Notice: Undefined index: edit in C:\xampp\htdocs\tibia\addnews.php on line 8
 
don't work:/
-Luf_kG.png


I'm added all codes, and don't work,

u can fix? and add the server information
 
lol for me its working 100% , you added that query to phpmyadmin? cause the error is you donde get the text displayed

- - - Updated - - -

Great! Rep++

- - - Updated - - -

Still having some errors when I want to add news. It doesnt stop the posting though.

Code:
Notice: Undefined index: action in C:\xampp\htdocs\tibia\addnews.php on line 7

Notice: Undefined index: edit in C:\xampp\htdocs\tibia\addnews.php on line 8

What you mean by stop the posting'

- - - Updated - - -

@Wodian are you admin with the acc you addnews?
 
Sorry, I had wiped the table above the simple new system, Raggaer thank you very much, works great!
 
@Reggaer

It doesnt stop the posting means it will continue to make the post on the website without errors. Yes I am administrator on my aac.
 
I add to your script simply comment system
add to your mysql database
Code:
CREATE TABLE `znote_news_comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `news_id` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `name` varchar(50) NOT NULL,
  `metter` text NOT NULL,
  PRIMARY KEY (`date`),
  KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
and replace code from index.php to
PHP:
 <?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>

<h1>News</h1>
<?php
$id = $_GET['id'];
if($id !=""):
$id = mysql_real_escape_string($id);
$getnewsbyid = mysql_query("SELECT * FROM `znote_news` WHERE id = '$id'");
while ($parsenewsbyid = mysql_fetch_assoc($getnewsbyid)) {
	$title1 = $parsenewsbyid ['title'];
    $body1 = $parsenewsbyid ['text'];
    $date1 = $parsenewsbyid ['date'];
    echo '<table border="0" cellspacing="5"><tr>';
    echo '<td><strong><p><a href=index.php?id='.$id.'>'.$title1.'</strong> - posted on <strong>'.$date1.'</strong></p></tr></td>';
    echo '<td>'.$body1.'</td></tr></table>';
	echo '<div class="separator"></div>';
	if (user_logged_in() === false){
	echo '<h1>Sorry, you need to be logged in to do that!</h1>';
	echo	'<p>Please register or log in.</p>';
	}
	else
			echo '<form action="" method="POST">
  <p>
    <label for="addcoment">add coment</label>
    <textarea name="addcoment" id="addcoment" cols="45" rows="5"></textarea>
  </p>
  <p>
    <input type="submit" name="submit" value="submit" />
  </p>
</form>';
echo '<div class="separator"></div>';
}
$getcomments = mysql_query("SELECT * FROM `znote_news_comments` WHERE news_id ='$id' ORDER BY `date` DESC");
while ($parsecomments = mysql_fetch_assoc($getcomments)) {
    $name = $parsecomments['name'];
    $matter = $parsecomments['metter'];
    $date = $parsecomments['date'];
	echo '<table border="0" cellspacing="5"><tr>';
	echo '<td><strong><p>'.$name.'</strong> - posted on <strong>'.$date.'</strong></p></tr></td>'; 
    echo '<td>'.$matter.'</td></tr></table>';
	echo '<div class="separator"></div>';
	};

if (isset($_POST['submit'])) {
    $news_id = $id; 
    $matter = mysql_real_escape_string($_POST['addcoment']);
    $name = $user_data['name'];
    $date = date("Y-m-d G:i:s");
	$addcomment = mysql_query("INSERT INTO `znote_news_comments` VALUES ('','$news_id','$date','$name','$matter')");
    header("Location: index.php?id=$id");
	echo 'addws';
     };
	else:

$getnews = mysql_query("SELECT * FROM `znote_news` ORDER BY `id` DESC LIMIT 3");
while ($parsenews = mysql_fetch_assoc($getnews)) {
    $id = $parsenews['id'];
	$title = $parsenews['title'];
    $body = $parsenews['text'];
    $date = $parsenews['date'];
    echo '<table border="0" cellspacing="5"><tr>';
    echo '<td><strong><p><a href=index.php?id='.$id.'>'.$title.'</strong> - posted on <strong>'.$date.'</strong></p></tr></td>';
    echo '<td>'.$body.'</td></tr></table>';
}
endif;
?>
<?php
include 'layout/overall/footer.php'; ?>
sorry if this code is exploitable but i'm not php programmer
sorry for my English
mylfu
 
Thanks nice little news system you created. I made some minor changes, it was nice to start with this instead of doing it from scratch.
 
No problem, thats why I post this here also, to help people or get help maybe.. xD
 
Back
Top