News system with comments
38,879 ViewsPHP Tutorials March 7th, 2007
The script is all based on PHP with a bit of MySQL (to store the comments and news posts) and also we will be using some javascript for the comments system.
Well enough jibber-jabber, let's get started.
First off we are going to have to create our database. I am using cPanel so I can create my databases from there. I am going to call my database news with a username of script and a password of tutorialcode.
Whenever you create a database in cPanel your database and username are given a prefix. This prefix is pre-determined by what your username is to login to cPanel. So for me this is tutorial. (IE : My database is now tutorial_news and my username is tutorial_script)
Now we need to create the tables in our database to hold the news posts and the comments.
Let's start off by creating out news posts table.
-
CREATE TABLE news_posts (
-
id INT(11) NOT NULL AUTO_INCREMENT,
-
title VARCHAR(70) NOT NULL,
-
author VARCHAR(50) NOT NULL,
-
post TEXT NOT NULL,
-
DATE DATETIME NOT NULL,
-
PRIMARY KEY (id)
-
);
This will create our news_posts table in which our news posts will be stored in, this just creates a table that has 5 rows, the first row will be our news posts ID. This number will auto increment (Meaning it will go up automatically) and this number will never be duplicated for that row. Then I have a title row, this will store the title of our news posts, then I have an author row, this will store the author of the news posts, then we have our post row. This will store the actual text for our news post. Then I have a row title date. This will be automatically inserted at the exact moment that it is inserted into the table. Then we create a PRIMARY KEY for our ID row, this is to guarantee that the number entered in the ID row is always unique, since all of our news posts are unique.
Now let's create our comments table. Since we will only want to display each comment that applys to the news posts they were posted on this table will require 2 id fields, 1 id field will be the actual ID of the comment, and the other ID field (we will call it nid) will have the number of the news post that the comment is posted for. So when we go to retrieve our comments, we can retrieve the right comments for that news post.
-
CREATE TABLE comments (
-
id INT(11) NOT NULL AUTO_INCREMENT,
-
nid INT(11) NOT NULL,
-
title VARCHAR(70) NOT NULL,
-
author VARCHAR(50) NOT NULL,
-
comment TEXT NOT NULL,
-
DATE DATETIME NOT NULL,
-
PRIMARY KEY (id)
-
);
This table is pretty much the exact same as our news_posts table with the exception that I have added a nid row (which I explain above) and also instead of a row called post it is now named comment.
Now let's get started with the actual PHP code of this project. First we are going to start off by creating a file called mysql_connect.php
-
<?php
-
-
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
-
?>
This part of our script actually connects to our database. It first defines 4 variables. Each variable is a part of our database (Host, username, database and password). So for this part of the tutorial insert your database specifications. I have left comments in the code to help better explain this. As you can see I input my database specifications for the database that I created earlier into the quotes.
Now save this file as mysql_connect.php and upload it to your webserver. If you now visit it on your webserver (ex : www.yourwebsite.com/mysql_connect.php) you will see a blank page, this means it worked. If you see any errors then that means the connection to the database did NOT work. This means you must have input your database specifications in wrong. Once you finally get a blank white page you may continue.
Next we are going to create the admin part of our script. So we are going to create a file called addnews.php.
For this script I will not be including any login authorization or admin authorization to add news, delete news or edit news. If you are to use this script on your own website it is recommended that you place the script in an area that requires login from an admin.
-
<?php
-
include ('mysql_connect.php');
-
echo '<p><font color="red">You need to enter a title.</font></p>';
-
} else {
-
$title = $_POST['title'];
-
}
-
-
echo '<p><font color="red">You need to enter a name.</font></p>';
-
} else {
-
$name = $_POST['name'];
-
}
-
-
echo '<p><font color="red">You need to enter a message.</font></p>';
-
} else {
-
$message = $_POST['message'];
-
}
-
-
if ($title && $name && $message) {
-
$query = "INSERT INTO news_posts (title, author, post, date) VALUES ('$title', '$name', '$message', NOW())";
-
-
if ($result) {
-
echo '<p><font color="red">News was added!</font></p>';
-
} else {
-
echo '<font color="red"><p>News could not be added! Please try again.</p></font>';
-
}
-
} else {
-
echo '<p><font color="red">Please fill in the appropriate information</font></p>';
-
}
-
}
-
?>
-
-
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
-
<p><b>News Title :</b><br />
-
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>" /></p>
-
-
<p><b>Name :</b><br />
-
<input type="input" name="name" size="15" maxlength="35" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
-
-
<p><b>Message :</b><br />
-
-
-
<p><input type="submit" name="submit" value="Add News" /></p>
-
<input type="hidden" name="submitted" value="TRUE" /></p>
-
</form>
Now lets break this file down into pieces for better explanation.
Alright, at first glance this piece of code may seem daunting, but fear not it is quite easy. All we do here is first start off our PHP document with <?php. Then we use a function called isset(). What this function does is check if a form is submitted. So here we check if $_POST['submitted'] was submitted using the isset() function. If it was submitted then we continue on.
Then we include our mysql_connect.php file, this is so now we have an active connection to our database so we can insert our news posts.
Then we use a new function called empty(). This checks to see if a form field was entered as empty or not. In this script we check if the field $_POST['title'] was empty or not. In this case if the field is empty then we continue onto the next part where we display an error telling the user they left the field empty, if the field was NOT empty then we come to the part of the code where we create our variable $title and give it the value of our field by using $_POST['title'].
Then we have 2 more form validations after this one that are exactly the same. (Except for the field name of course, so just replace that if you need better explanation with the appropriate form field name, and also the variable name.)
-
if ($title && $name && $message) {
-
$query = "INSERT INTO news (title, name, message, date) VALUES ('$title', '$name', '$message', NOW())";
More code explanations! This part of our script is where our query is created, this is the query we will be using to insert our news posts into our database. We first create a variable called $query. We will then give it the value of our actual query. So we use an INSERT query and insert the appropriate values into the appropriate places.
I use a NOW() function for our date row, this will insert our date at the exact moment of posting. Then we create a variable called $result. This is where we execute our query using the mysql_query() function. I add an @ sign before the function so that if any errors happen it will NOT display the default ugly PHP errors.
The final part of our PHP code for this file is where we check if our variable $result is TRUE or FALSE. If it is TRUE (Which means the query worked), we display a message to the user saying it worked. If it did NOT worked then we display a message telling the user. Then we finish our PHP document with the ?> tag.
-
<form name="addnews" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
-
<p><b>News Title :</b><br />
-
<input type="input" name="title" size="25" maxlength="60" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>" /></p>
-
-
<p><b>Name :</b><br />
-
<input type="input" name="name" size="15" maxlength="35" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
-
-
<p><b>Message :</b><br />
-
-
-
<p><input type="submit" name="submit" value="Add News" /></p>
-
<input type="hidden" name="submitted" value="TRUE" /></p>
-
</form>
Then we create our HTML form, I use stick forms so the user doesn't lose the information they have input. Learn more about sticky forms by reading our tutorial.
Then I just create basic input fields, and a text area for our news post to be entered in.
Now we will create a page where we can view the news posts that we enter. I am going to call this file news.php
-
<html>
-
<head>
-
<script type="text/javascript">
-
function openComments(url)
-
{
-
comments = window.open(url, "Comment", "menubar=0,resizable=0,width=380,height=480")
-
comments.focus()
-
}
-
</script>
-
</head>
-
<body>
-
<?php
-
include ('mysql_connect.php');
-
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
-
-
if ($result) {
-
$url = 'comments.php?id='.$row['id'];
-
'.$row['sd'].'<br />
-
Posted by : <b>'.$row['author'].'</b><br />
-
'.$row['post'].'<br />
-
<a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>';
-
}
-
} else {
-
echo 'There are no news posts to display';
-
}
-
?>
-
</body>
-
</html>
This is just a little bit of code (Thats all we need to display our news )
I will just explain it all here, first we start off by creating our HTML document, then in the head of our document we create a new javascript function by using the <script> tag. This is just a simple function to open a new window with a url that we input.
So all we are doing is creating our function, I am calling it openComments. Then we give it a new parameter called url. This where we input the URL of our comment for our specific news post. Then we just use the new.window() function to open the function with our URL. If this all seems fuzzy to you take a look at our tutorial on Javascript functions.
Then we start our PHP document. We include our mysql_connect.php since we will need our database to retrieve our news posts. Next we get right down to it and create our query, we select everything from our news_posts table, we use the DATE_FORMAT MySQL function to format our date to our liking. Then we execute our query and set the result to the variable of $result. Then we check if our query went off without a hitch, next we need to display our news posts. So I have used a while() loop to do this.
I am creating a new array using our result from our database and calling this array $row, I am defining it as MYSQL_ASSOC. This means our array wont be numbers for the rows, it will be the actual row names. If you wanted to use numbers you can use MYSQL_NUM instead. Then we define the URL that we are going to be using for our javascript function, after that we just echo out the information for our news post, the title, author, date it was posted and the actual news post its self. Then we create a link that actually uses our javascript function. We put in our $url variable for the url parameter we defined in our javascript function earlier. Then we just need to make an } else { statement if there are no news posts to display and finish off our PHP document and thats it!
Alright, only 3 more small files to create and your done! Our next file that we are creating will be the file where we view and add new comments to our page. I am calling this file comments.php.
-
<?php
-
include ('mysql_connect.php');
-
-
$id = $_GET['id'];
-
} else {
-
echo 'Please select a news post to view the comments.';
-
}
-
$query = "SELECT * FROM comments WHERE nid = $id";
-
-
<b>Author : </b>'.$row['author'].'<br />
-
<b>Comment : </b>'.$row['comment'].'<br />
-
<hr width="80%" />';
-
}
-
-
-
$errors[] = '<font color="red">Please enter in a title.</font>';
-
} else {
-
$title = $_POST['title'];
-
}
-
-
$errors[] = '<font color="red">Please enter in your name.</font>';
-
} else {
-
$author = $_POST['author'];
-
}
-
-
$errors[] = '<font color="red">Please enter in a comment.</font>';
-
} else {
-
$comment = $_POST['comment'];
-
}
-
-
$query = "INSERT INTO comments (nid, title, author, comment, date) VALUES ($id, '$title', '$author', '$comment', NOW())";
-
-
if ($result) {
-
echo '<font color="blue">Your comment was added succesfully!</font>';
-
} else {
-
echo '<font color="red">There was an error when submitting your comment, please try again.</font>';
-
}
-
} else {
-
echo '<b>There were a couple of errors -</b><br />';
-
foreach ($errors as $msg) {
-
echo " - $msg<br />\n";
-
}
-
}
-
} else {
-
?>
-
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" />
-
<p>Comment Title : <input type="text" name="title" maxlength="70" value="<?php if(isset($_POST['title'])) echo $_POST['author'];?>" /></p>
-
-
<p>Your Name : <input type="text" name="author" length="25" maxlength="50" value="<?php if(isset($_POST['author'])) echo $_POST['author'];?>" /></p>
-
-
-
<p><div align="center"><input type="submit" name="submit" value="Submit Comment" /></div></p>
-
<input type="hidden" name="submitted" value="TRUE" />
-
</form>
-
<?php
-
}
-
?>
-
<div align="center"><a href="javascript:window.close()">Close this window</a></div>
This is our code for displaying and adding new comments. First we include our mysql_connect.php file so that we can use our database information. Then we check to see if $_GET['id'] was submitted or not, this is what is in our URL. (EX : www.yourwebsite.com/comments.php?id=1). Then we create our query to retrieve any comments from our database.
Then we do some form validation, this is the exact same is in previous files. Except different form fields, then if there are no errors we create our query to insert our data into our table. Then at the end of our script we just create the form that people use to insert there comments. Pretty straight forward eh?
Next we are going to create the file for deleting news posts. But before we do that, we need to create a file to manage our news posts. This will be called news_manage.php.
-
<?php
-
include('mysql_connect.php');
-
$query = "SELECT id, title FROM news_posts";
-
-
if ($result) {
-
echo '<div align="center">
-
<table border="0">
-
<tr>
-
<td><b>ID</b></td>
-
<td><b>Title</b></td>
-
<td><b>Delete</b></td>
-
<td><b>Edit</b></td>
-
</tr>';
-
-
echo '<tr>
-
<td>'.$row['id'].'</td>
-
<td>'.$row['title'].'</td>
-
<td><a href="delete_news.php?id='.$row['id'].'">Delete</a></td>
-
<td><a href="edit_news.php?id='.$row['id'].'">Edit
-
</tr>';
-
}
-
} else {
-
echo 'Sorry, but we could not retrieve any news item records.';
-
}
-
?>
This is just a simple small part of code that retrieves our news posts from our database and displays them in a table with Delete and Edit links beside each one. Save this file as news_manage.php
Now we create our script to delete our news. This will be called delete_news.php.
-
<?php
-
include('mysql_connect.php');
-
$id = $_GET['id'];
-
-
$query = "DELETE FROM news_posts WHERE id = $id";
-
-
if ($result) {
-
echo '<h3>Success!</h3><br />
-
The news item was deleted succesfully.<br /><br />
-
<b>Options :</b><br />
-
Delete or Edit another news item : <a href="news_manage.php">[X]</a><br />
-
Add a new news item : <a href="addnews.php">[X]</a><br />';
-
} else {
-
echo 'We are sorry to inform you but the news item you chose to delete could not be deleted. Please feel free to try again';
-
}
-
} else {
-
echo 'Invalid news item, please choose a news item.';
-
}
-
} else {
-
echo 'Before visiting this page please choose a news item to delete first!';
-
}
-
?>
This is just another small piece of code that retrieves the specific news post from the database that corresponds to the ID that was passed through the URL. If it is found then it deletes it from the database and displays a message saying if it worked our not. Now we need a file to edit our news posts, this is pretty much the exact same as our add news post except the values of the form fields is already put in. I am going to call this file edit_news.php.
-
<?php
-
include('mysql_connect.php');
-
$id = $_GET['id'];
-
$id = $_POST['id'];
-
} else {
-
echo 'Please choose a news post to edit.';
-
}
-
-
-
$errors[] = 'You forgot to enter a title.';
-
} else {
-
$title = $_POST['title'];
-
-
}
-
-
$errors[] = 'You forgot to enter an author.';
-
} else {
-
$name = $_POST['name'];
-
}
-
-
$errors[] = 'You forgot to enter a message';
-
} else {
-
$message = $_POST['message'];
-
}
-
-
$query = "UPDATE news_posts SET title='$title', author='$name', post='$message' WHERE id=$id";
-
-
if ($result) {
-
echo "News Post Has Been Updated!";
-
} else {
-
echo "News post could not be updated.";
-
}
-
} else {
-
echo 'News post could not be updated for the following reasons -<br />';
-
foreach ($errors as $msg) {
-
echo " - $msg<br />\n";
-
}
-
}
-
} else {
-
$query = "SELECT title, author, post, id FROM news_posts WHERE id=$id";
-
-
$title = $row['0'];
-
$name = $row['1'];
-
$message = $row['2'];
-
-
if ($num == 1) {
-
echo '<h3>Edit News Post</h3>
-
<form action="?id=edit_news&num='.$id.'" method="post">
-
<p>News Title : <input type="text" name="title" size="25" maxlength="255" value="'.$title.'" /></p>
-
<p>Name : <input type="text" name="name" size="15" maxlength="255" value="'.$name.'" /></p>
-
<p>Message : <br /><textarea rows="5" cols="40" name="message">'.$message.'</textarea></p>
-
<p><input type="submit" name="submit" value="Submit" /></p>
-
<input type="hidden" name="submitted" value="TRUE" /></p>
-
<input type="hidden" name="id" value="'.$id.'" />';
-
} else {
-
echo 'News post could not be edited, please try again.';
-
}
-
}
-
?>
This is basically the exact same as our addnews.php script except for the form part. Before we display the form we make a query that selects a news post from the database that corresponds to the id number that we passed through the URL. Then it sets the value=" " attribute of each of the form fields to the appropriate pieces of information from the data that we extraced from the database.
And that's it! Phew, that was long! I hope you learned something from this tutorial and plan on using it on your very own website! All the files have been tested and work.
If you have any questions feel free to send us an email using the contact form located on the site.
Thanks
Sean
Extension: Search Form

(47 votes, average: 4.7 out of 5)










March 7th, 2007 at 9:38 pm
Awesome tutorial, works perfect and is just what I was looking for!
March 8th, 2007 at 10:21 pm
Great tutorial! Described very well, and with a great outcome!
March 9th, 2007 at 1:50 pm
Great Tutorial! Just what i was looking for...just wondering if anyone is having trouble putting news stories over about 10 lines in?? It wont allow me to put in anything more than a few lines...any ideas??
March 9th, 2007 at 3:03 pm
Hey there Matt, I'm not 100% sure what your problem is. Does it not let you type anymore, or does it give you an error when you submit?
March 13th, 2007 at 8:02 am
Hey. If i input a story over a certain length, i get an error. However i am able to go into the sql database and edit the field manually to contain the full story.
Any ideas?
Thanks
March 13th, 2007 at 11:49 am
That is weird, can you tell me the error that you get? I am maybe thinking that it is because the post area is defined as TEXT, which allows you to input a maximum of 65,535 characters, so if you are writing messages that have even more characters then that, if you would like to input more then in your PHPMyAdmin (or whatever you use to administer your tables) input this SQL query -
ALTER TABLE news_posts CHANGE COLUMN post post MEDIUMTEXT
That will allow you to input 16,777,215 characters. I hope that is enough for you! If that doesn't fix the problem, can you tell me the error.
Thanks
Sean
March 13th, 2007 at 12:27 pm
Hi Sean
Thanks for your reply.
Thats fixed the problem! Great Job!!
Matt
March 14th, 2007 at 5:58 pm
hey, i got a problem i get this error...
Parse error: parse error, unexpected T_STRING
March 16th, 2007 at 2:58 pm
nice
March 17th, 2007 at 2:56 pm
Hi! Your tutorial is the best, but I have a problem.
I can edit data, only if I have one record in database.I click "Edit" and it works! But if I
insert 2 or more records and try to get "Edit"..there is an error "'News post could not be edited, please try again"! Why if(num==1) in code?
Thanks a lot!
March 18th, 2007 at 9:32 am
To your question about the if ($num == 1), that is because when we select 1 entry in the database to edit, we want to make sure that it is only 1 entry and we don't select more (or less) then that.
What is the error you get when you try and click edit?
March 19th, 2007 at 6:02 am
Hey, can someone give an example of this comments system? I'll try it later today!
March 19th, 2007 at 9:10 am
Hey, i'd like to see some examples. I'll try this tutorial this evenin'
March 19th, 2007 at 10:35 am
Hey there,
I will get up a live example of this before this evening and add the links to the demo at the end of the tutorial.
March 20th, 2007 at 2:35 am
Thanks! I just copied again your code, replace
echo'' part with mine, and now it works.
I don`t know what was wrong, but it`s OK now!
March 20th, 2007 at 11:03 am
Alright, good to hear you got it working, it has worked for everyone else so I'm not sure why it wouldn't work for you.
March 21st, 2007 at 9:23 pm
when i click on the "add new comments..." it opens the window and gives me the "please select a news post to view comments" message and nothing else on the window. im not sure what i did wrong.
March 21st, 2007 at 10:04 pm
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
echo 'Please select a news post to view the comments.';
exit();
}
That is the code for where your getting your error. It seems like it's not submitting an ID when you click on the comment link.
What is the URL of the link when you click for the comments?
March 22nd, 2007 at 7:38 pm
http://www.yordymusic.com/comments.php?id=1 by looking at that it seems like it's doing what it's supposed to so i dont know.
March 22nd, 2007 at 7:45 pm
fixed it....sometimes i forget that stuff in php is case sensitive.
March 24th, 2007 at 4:28 am
The news system works pretty good!
WoW!
March 24th, 2007 at 1:09 pm
Is there a way to change it so the latest news post is showing first? I've been trying to figure it out.
March 24th, 2007 at 7:40 pm
Yes, you just need to change your SQL query that retrieves the posts.
In news.php, change -
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
To -
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC";
If that doesn't work, change DESC to ASC, I get mixed up with those 2 quite often
March 30th, 2007 at 7:02 pm
Hi Sean!
I have a problem i get this error,please help me
Parse error: syntax error, unexpected T_STRING in D:\htdocs\vjezba\mysql_connect.php on line 5
April 13th, 2007 at 8:59 am
Hi there,
I've been trying to figure out how to show
only the 3 latest news posts on the main page
of a website I'm working on, and to also
make the comments pop-up page have a scroll
bar instead of having a fixed height and width
that cannot be resized by hand, nor have
the scroll bar.
Thanks a lot! Great news script btw!
April 17th, 2007 at 10:29 pm
Thanks , its very nice!
April 18th, 2007 at 4:26 am
I think Im gonna try this tut, but Im not all that proficent with php yet, so what Im wondering is this;
Is it possible to set so only ONE news article shows, and the rest get stored in a archive?
April 19th, 2007 at 1:59 pm
Thanks for the tutorial.
On news.php, the expression "if ($result)" should be "if (mysql_num_rows($result)>0)". The expression will not be false even if the rows are empty.
April 19th, 2007 at 2:17 pm
Also, it would be better to not use empty() but something like if(isset($_POST['title']) && trim($_POST['title']!='')). Empty returns true for 0 (which I dont know why you would put that but it isnt invalid) and it also doesnt check for empty spaces.
April 22nd, 2007 at 7:30 am
hi this tutorial is great.But i have a little problem.Exactly when i am trying to add it's says News could not be added! Please try again.I saw this message after changing the query to display the first news post as first.
I think the problem is in addnews.php file in the line of query but i don't know what to do ?
Also i changeed in the mysql the table exactly in the news the text area to mediumtext.
April 22nd, 2007 at 7:52 am
I do like this tutorial great.
But was wondering if there was a way to edit comments that people post?
Especially if its something rude etc?
Would really appreciate this.
Thanks
April 22nd, 2007 at 9:17 am
@chris - If anything the error would be when your selecting the data from the server to display on the news.php page.
Send me an e-mail using the contact form on this site and we can discuss it further.
@scott - Same thing for you, just send me an e-mail using the contact form on this site and I will send you some code and show you how to use it for editing the comments made on news posts.
May 7th, 2007 at 7:59 am
Hey there. i wonder if it is possible to change so u can just show the last 3 news on the older ones u can see by clicking on another side number like. 1-2-3 for example. I would be glad if u could respond to this and had a solution. Because i dont want the page to grow to much from old news taking place.
Great tutorial btw. i rly liked it =)
May 19th, 2007 at 6:43 am
Hey,
Just a real quick question if you don't mind. I made a small change by deleting the javascript and making comment.php to be shown on a normal page. After that I combined news.php and comment.php together so that the news are at the top of the page and the comments are displayed right after the news. Now it looks a bit silly because it displays all the newsposts before the comments. Is there a way of changing the script in a way that it displays the comments right after the newspost they are related to?
Thanks
May 22nd, 2007 at 10:59 pm
I made a modification so if for some reason someone managed to hack into the addnews page and attempted to add javascript it would block it. the code below is only an example for message field. I made a small change in the message field and called it $message2 = $_POST['message'];
Then I used some regex to check for anything with You need to enter a message.';
} else {
$message2 = $_POST['message'];
}
//checking for vb/javascript script
$urlreg = $message2;
if( preg_match('/Scripting languages are not allowed';
} else {
$message = $_POST['message'];
}
June 4th, 2007 at 1:36 pm
Gah! It doesnt work for me, I click add news it goes blank but doesnt add it to the mysql table. ANy ideas?
June 4th, 2007 at 6:47 pm
Hello i found a problem with deleting news.
when you delete one old news, and add another one it will be given the deleted news Id. so if i have 2 news and deletes the first, then i write a new... the new news will take the first place where the one i deleted were.
how to prevent that this happens? and the news will come after eachoter?
sorry for bad english.
June 8th, 2007 at 3:20 am
In the addnews.php I have message when I press add news button:Fatal error: Call to undefined function: escape_data()
June 12th, 2007 at 2:16 am
[...] (No Ratings Yet) Loading ... PHP Tutorials June 12th, 2007 Hi, this is an extension for "News System with Comments". If you haven't taken the tutorial already, I seriously recommend you do because we will be using [...]
June 12th, 2007 at 1:22 pm
Hey,
i would like to order it and put title etc. in tables... is it possible ? and how ?
June 15th, 2007 at 10:35 am
You would like the titles to be ordered by the title of the news post?
June 21st, 2007 at 11:06 am
Parse error: syntax error, unexpected T_STRING in /home/jalkson/public_html/mysql_connect.php on line 9
can't get it working. On the step where I need to see a blank page
June 23rd, 2007 at 10:26 am
alright, I got it work out. I am done except for one item.
I combined the news page and comments page, so when you click comments you can see the news article you are commenting, problem is it shows all the news items not the one you clicked. Solution?
thanks.
June 28th, 2007 at 8:22 am
Hi Nouman,
I've same problem with mysql_connect.php as you. How did you solved this problem?
Thanks
June 28th, 2007 at 6:06 pm
this is what I used to get it to work:
July 1st, 2007 at 2:54 pm
Hello,
I love this tutorial, it is great and I have learned a lot for this!
I was wondering, how would I make the posts go from (what it is now) 1st posted to latest posted ---to---> latest posted to 1st posted.
Also how would I limit the number of posts on my page to say 3 and when that number is over 3 it creates a previous post page which will show 3 (that have moved from the home because of the 3 post limit) etc.?
Thanks so much
-Adam
July 1st, 2007 at 2:58 pm
@Corona,
Simple little fix for the mysql_connect.php
He just missed the two // for a comment which threw the whole script off (no biggie) Here is the working script:
enjoy
and any answers to my question above would be great!
-Adam
July 4th, 2007 at 5:47 pm
Hey, me again!
I want to put the Content etc. in tables!!! because i want to make a newsbox for the news
^^ is it possible ? hope you understand my question^^
July 4th, 2007 at 7:13 pm
@Snaper
Hello, yea you can do that, You take the news.php info, put the around the php part in the body. And have it load a .css file. Set the in the .css to have it read out your box. EX:
css ex)
#news{
width: 400px;
height: 400px;
background-color: #000000;
float: left;
font-family: tahoma;
font-size: 12px;
color: #ffffff;
}
-Adam (ps if you need more help email me aneveu[at]verizon.net
July 8th, 2007 at 3:01 pm
Hi Adam,
Thanks for your explains en the problem is solved.
And I'll try to explain your problem.
change in news.php:
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%d %M %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 3";
I hope that helps you.
Greetings
July 10th, 2007 at 12:45 pm
Hello again,
I want to show the comments on the same page as news.php
Who can explain me how?
July 10th, 2007 at 3:55 pm
hmmm Adam,
i worte you a mail! but you dont answere
July 14th, 2007 at 5:07 pm
@Snaper
Yea sry I was on vacation for the last 7days. msging back
-Adam
July 14th, 2007 at 5:40 pm
@Corona
Hey, sry I just noticed that post of yours
thank-you so much for the reply and the help, I will try that out right now after I finish messaging back Snaper (above).
But a quick question on your help, after there are 3 posts on the page will it create a new page???
Thank-you very much for your great help!
-Adam
=====Quick Reference Tutorial - How to show the news posts in a box using CSS (Help for Snaper)=======
====Tutorial====
Question: How can you show the posts in a box for better showing?
Answer: Follow this tutorial
1) After testing all the coding required for the tutorial above and making sure that the posting will even work by adding news and viewing through news.php you can follow this tutorial.
2) In the same folder that holds news.php and mysql_connect.php create a file named index.php
3) Also in the same folder create a CSS file named style.css
4) For index.php you will enter everything that is in news.php. So type the following code for news.php given in the tutorial plus a little additions made by me
==Code==
Beefteck.com - Web Design and Software Solutions
@import "style.css";
function openComments(url)
{
comments = window.open(url, "Comment", "menubar=0,resizable=0,width=380,height=480")
comments.focus()
}
'.$row['title'].'
'.$row['sd'].'
Posted by : '.$row['author'].'
'.$row['post'].'
Add new comment or view posted comments';
}
} else {
echo 'There are no news posts to display';
}
?>
====End Code====
Now to explain the additions to the news.php code. Basically all I did was add titles, for the file to import the style.css, and for the style.css to give the news posts their "body" which is why the is around the code.
5) So now that the index.php is finished we are going to work on the style.css which is going to give the page its shape and body. I am going to be going with a simple layout. So in the file style.css type this in:
====Code===
#content {
width: 520px;
margin-left: 10px;
margin-right: 0px;
margin-top: 10px;
margin-bottom: 10px;
float: left;
background-color: #5f5f5f; /* Light Gray*/
font-family: tahoma;
font-size: 11px;
color: #ffffff; /* White*/
padding: 5px;
}
body {
margin: 0px auto;
text-align: center;
background-color: #5f5f5f; /* This is set to black, background of the site*/
}
====End Code====
Ok so what that just did was give the posts in a box (gray) around it with white text, and changed the fonts and give the body a background color(black).
Try it out edit it enjoy it lol, this was a quick example on how you can use CSS to work with the news.php coding. Please feel free to use and learn with this code, if you like it link to me at www.beefteck.com
====End Of Tutorial===
July 14th, 2007 at 8:13 pm
@Corona
Nice, just tested that out and love it
ty so very much for your help with that little prob. Now I believe my only little problem is now is to find how to have it do this:
When post is added, post will be added to the news.php but the title will be a link to also a page that only has the post with comments below it. comments are posted below it and read below the post...
lol no clue how to do that....i am also having problems with securing the page
but this is all just being made and tested right now any way so atm it does not really matter...
anyway ty for your help and if anyone can help me with this other problem that would be great
-Adam
July 15th, 2007 at 1:52 pm
Hi Adam, thanks for your answer on my question, but I think that I was not clear enough...so I want to show the comments under the news, not in a new window. Do you know how?
And I'm glad to hear that I can help you, but I have the same problem as you about title. And I don't know how.
But I'm learning php too.
Greetings
July 15th, 2007 at 7:26 pm
@Corona
hmmmm lol I would want that lol, here is an example of it (friends site) he used this tut to make it, maybe he can help us lol... www.greggrillo.com
Otherwise at this point I am 100% stummped about that.. :'(
Any1 can help us that would b great
-Adam
July 18th, 2007 at 6:55 pm
Last question
i want to show the latest news up.
how can i do it ?
July 20th, 2007 at 2:14 pm
@Snaper
Replace this code in news.php:
" $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";"
with this code:
" $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%d %M %Y') as sd FROM news_posts ORDER BY date";"
ty to Corona
August 4th, 2007 at 2:19 pm
This is a great tutorial!!..I am having one issue with the following:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\channel730.com\comments.php on line 18
i check cases and spelling bu cant find anything wrong. I'm still a newbie to this and would be greaful for any help offered.
August 4th, 2007 at 2:20 pm
Also...is there a tutorial out there that would help you create a blog/comment area like this one here?
thanks
August 8th, 2007 at 8:50 pm
This tutorial it's great.
Working perfectly.
Great job.
August 15th, 2007 at 1:17 pm
works like a charm but the news is posted in ASC order, i cant find out how to get it DSC
August 16th, 2007 at 9:33 pm
Awesome awesome awesome! I love it, but how do I get it to post Newest to oldest? Because it's showing my oldest posts at the top and newer ones at the bottom. Drop me an email or something to help a bit, please. Thanks man!
August 17th, 2007 at 2:02 am
YES! for the age long question that i even asked, How to make the news from newest to oldest ( desending order ) in your news.php in the code
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
replace it with an order by DESC or this
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY id DESC";
August 18th, 2007 at 1:16 am
I am having a problem with the edit_news part of the script. I am only getting "Please choose a news post to edit." and not the news posts that I need edited. Here is the code, please help.
If you need to look at it manually, just tell me in the comments and I will send you the link.
...
';
foreach ($errors as $msg) {
echo " - $msg\n";
}
}
} else {
$query = "SELECT title, author, post, id FROM news_posts WHERE id=$id";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$title = $row['1'];
$name = $row['0'];
$message = $row['2'];
if ($num == 1) {
echo 'Edit News Post
News Title :
Name : '.$name.'
Message : '.$message.'
';
} else {
echo 'News post could not be edited, please try again.';
}
}
?>
August 18th, 2007 at 1:17 am
I haven't edited anything. Just changed the mysql_connect.php to db.php
August 18th, 2007 at 1:22 am
I am retarded, I totally forgot news_manage.php was the file to use to edit not edit_news.php...
August 19th, 2007 at 1:06 pm
Hello!!! I have tried to add news but it wont work!!! I copied and pasted the code the second time to make sure i typed it correct but i just dont know
i havent set it to to the main page but the files news.php shows the news but no news /admin/addnews.php is where i add news but that doesnt work . Anybody can help?
August 20th, 2007 at 7:53 am
Hey its me again ! I fixed the first thing ! But now my problem is that i get the error :Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/r6079rea/public_html/tr/comments.php on line 26
I think its something to do with the MYSQL_ASSOC
Anybody help?
August 20th, 2007 at 7:21 pm
Hello! I hat this to work perfectly but for I would like to put in an field with 4 options. Any ideas on how to get this to work in the addnews.php file?
Cheers,
Simon
August 24th, 2007 at 1:32 pm
@Sean: It is not problem with the MYSQL_ASSOC because it says: supplied argument is not a valid MySQL result resource. result resource. there is a problem with the variable $result.
Try
echo $result;
or:
print_r($result);
August 26th, 2007 at 2:22 am
This is a great tutorial. I used it as a basis to make my own MySQL/PHP systems. With a few adjustments you can make great stuff through this. Maybe a next article could be about improving it's security.
August 28th, 2007 at 11:15 pm
Simon, you said somthing about four options, do you mean adding a function like an extra text field? If you specify what you want an extra feild would be i would gladly hand you the code and proper mysql table.
September 1st, 2007 at 3:12 pm
Hello,
ok well I was looking for a little help lol for adding another text area when posting news.
I wanted it to be a drop down box that would have categories in it and when reading the news it would show the category in the news posts.
Any help would be fine lol
thank-you
-Adam
September 6th, 2007 at 6:13 am
i have a problem witch id wen i write comments.php?id=100
an get me to write a comment how to macke if don't have id 100 to shou no news witch that id
September 15th, 2007 at 1:53 pm
I have a few questions on this.
First being is it possible to have the news posted show only a small portion of it, with the option and a link to the full story.
Second of all, how could i create categories?
September 16th, 2007 at 4:48 pm
Scott, to anwser your question about a link to a page with just the full article on it I have the solution.
First create a page called news_article.php
Then place this code into your page and make sure you edit this text to your settings if they may.
-----------------------START-CODE------
function openComments(url)
{
comments = window.open(url, "Comment", "scrollbars=yes,menubar=0,resizable=0,width=300,height=480")
comments.focus()
}
'.$row['title'].''.$row['sd'].''.$row['post'].'Posted by - '.$row['author'].' Post a Comment
';
}
} else {
echo 'There are no news posts to display';
}
?>
------------------------END-CODE-------
And all you need to do is on your news.php file is create a link for each news post, or copy and paste over your '.$row['title'].'
-------------------------------------------
'.$row['title'].'
-------------------------------------------
And you should have a news.php with the title being the link to the page with only the one news article on it.
Hope that works and if not just reply
September 19th, 2007 at 8:50 am
after adding news, and another news say for example 100 news, all the news are loaded onto one long whole page. how do u limit for example 10 news onto a page? and then the other 10 news onto the next page and so on.. what i am trying to say is that how do you create previous/next button? so that all the news are not uploaded onto a single page. thanx...
September 28th, 2007 at 12:35 am
This tutorial is brilliant ... can you also tell me how to include login authorization or admin authorization for add/deleting/editing the posts?
September 28th, 2007 at 2:20 pm
Also it will be helpful if there's an test page or an example is provided ...
October 4th, 2007 at 12:50 am
Hi there , this is a nice tutorial ,but how can we add pagination to it?
November 7th, 2007 at 10:40 am
Hey there.I have a problem.When I click to add the news in addnews.php the screen becomes white.It doesn't display any errors or text.Please,tell me what could i've done wrong?(I'm a newbie so I could have easily made an error)
November 10th, 2007 at 9:54 am
Hey, cool script! But when I copy the codes than the number comes widht the code -_-
December 1st, 2007 at 7:43 am
this is definately the best tutorial for creating a news system ive found, its brilliant!
@rohisrin - for the security on my site i moved all the editing php pages to a seperate directory, and made a copy of the connecting php file to this directory, then i used my website control panel to put a password on the folder so no one can get into that directory without a password.
im also looking for a way to limit the ammont of articals displayed on each page so i dont get one massive news page. Ive read through everyones comments but cant see a solution.
also there is no way to edit/delete peoples comments, I dont want offensive comments on the site!
any help would be much appritiated - email me hello@pushmusic.org if you can help me out, please!
December 3rd, 2007 at 5:14 pm
Hi,
I didn't posted anything and still I don't see this "There are no news posts to display". What can be wrong?
LINE 26 ~ 28 @ news.php
} else {
echo 'There are no news posts to display';
}
Thank you for your attention.
January 5th, 2008 at 7:33 pm
And a happy new year to everybody,
especially to those who found this site.
This is great.
ThanX
January 6th, 2008 at 11:56 am
ohoh ... thank so much ... good tut ...
January 6th, 2008 at 11:57 am
however, i want using this board comments to multi-comments follow id that's id for content web. thanks reply.... i love it :d
January 21st, 2008 at 8:36 am
This script works great and is very useful although I do have a problem that when adding news if you have apotrophes in the text the script will reject it and say that the news can not be added.
EG
Heres the news isn't it wonderful
"NEWS CAN NOT BE ADDED"
Heres the news isnt it wonderful
"NEWS ADDED"
I hope there is a simple fix please
Regards
J
January 29th, 2008 at 3:44 pm
To all of you who have been trying to get comments to show under the news rather than in a pop-up window and can not seem to get it accurate:
I have found a solution. To email me on this, click on my name and I will help you with that.
January 29th, 2008 at 3:45 pm
Oh my bad, no link in my name. Use below:
iitanchicii[at]aol.com
February 7th, 2008 at 9:09 pm
I've copied each piece of code from here, and fixed the mysql comment bit. Yet I still can't load the page, it just shows up blank.
http://rmrevolution.com/users/jalk/cms/
If anyone has any thoughts, I'd love to hear them. ;]
February 24th, 2008 at 12:10 am
In edit_news.php, the first set of lines--
} else {
echo 'Please choose a news post to edit.';
exit();
}
more content here (including template of mine) is broken because of the exit(); , how can I work around this? Thanks
February 24th, 2008 at 1:54 am
Hey man, this script works great... but is there a way were I can just show one news item at once? Like news.php?id=1 or something like that?
February 26th, 2008 at 6:17 pm
Hey, I got it to work like I needed it to... but I have a question... how do I block all code that someone puts in the box? Like HTML, PHP, Javascript, all that. I would like to block all that type of code so I can't get hacked.
February 29th, 2008 at 2:28 pm
dude, your script is absolutely excellent.. i've tried it and perfectly running..
March 1st, 2008 at 6:17 am
Hi it's me again. Thanksfor the great tutorial, but I just wondering one thing.
How do I make the script to show how many comment was posted? It will be like this, instead of "Add new comment or view posted comments" link, I want to show that;
example: "(3) Comments" ..
So if one more comment was added it will be "(4) Comments" and so on..
Any idea guys? Thanks in advance
March 5th, 2008 at 8:55 pm
Figured it out just changed the DB code to
March 6th, 2008 at 10:16 am
I've gotten an error with the mysql_connect.php
Parse error: syntax error, unexpected T_STRING in /home/*******/public_html/mysql_connect.php on line 5
March 6th, 2008 at 10:20 am
Nevermind, I fixed it.
March 6th, 2008 at 10:24 am
Actually, I didn't fix it, still messed up.
March 18th, 2008 at 7:23 am
i am wondering..
if you delete a post the comments are not deleted?
how must the php be to get this solved?
March 21st, 2008 at 1:59 pm
Very good tutorial.
March 21st, 2008 at 8:55 pm
thats for sure, bro
March 24th, 2008 at 9:19 am
This tutorials is great, i'm going to use this on my site, but can you make a function so ppl. can enable user comment and not.
April 2nd, 2008 at 6:26 pm
I got the Same Error as Chris "News could not be added! Please try again." and i need to understand why.
@Admin, if you can please contact me on my Hotmail how to get this error straighten out, thankyou.
or anyone else that think they know what's up, please hit me up on extendedability@hotmail.com on MSN. thankyou
April 4th, 2008 at 3:12 pm
i got the error also for the first place.. but after alter it myself, i manage to solve it but forgot how-to.. anyway you can visit my site, i've apply the comment script there.. now looking for script that can show how many comment was posted... anyone know how to do that?
April 21st, 2008 at 5:43 am
Hi!
If you guys have problem with this:
Parse error: syntax error, unexpected T_STRING in mysql_connect.php on line 5
Edit mysql_connect.php line wich is:
DEFINE ('DB_NAME', 'database'); Insert your actual database name in the quotes.
to this:
DEFINE ('DB_NAME', 'wille1'); // Insert your actual database name in the quotes.
April 26th, 2008 at 6:58 am
Hi!
I use this news system and really like it!
I just want to add the time when someone make a comment.
How do I add the time to se when someone commented the news?
Thanks!
April 26th, 2008 at 7:05 am
Oh I forgott to ask.
Is there a way to make "BB codes" work when you wright a news?
Main thing is that (bold), (url) and (br) works.
Thanks again!
May 2nd, 2008 at 12:12 pm
good
May 10th, 2008 at 11:00 am
terrific.
It works wonders.
However,when I add news, the news has 4 paragraphs, but when i view it in news.php, it has only paragraph. I means there is no break between paragraph. Can anyone help me to formatting the news so that it has break between paragraph
June 3rd, 2008 at 1:57 pm
Hi toanbau,
You can do like me add a WYSIWYG editor to the Add News / Edit - Delete...
Use Tinymce.. it's easy to use..
June 11th, 2008 at 10:50 am
Thanks for this script, i read through all 116 replies and have come across some nice additional things i could install like the tinyMCE Editor.
As some guys already asked how can we make seperate pages like on a blog?
EG:
*****************
INDEX
- News1 with commentlink (Click -> Redirected to the whole News with comments on a seperate page, for example "index.php?site=news1)
- News2 ( "" )
- News3 ( "" )
NEWS1
- with comments and link back to the index
NEWS2
- with comments and link back to the index
NEWS3
- with comments and link back to the index
*****************
Thank you guys for hopefully answering, i would be happy if anyone knowing a solution would email me at admin[at]janschuster.com
Thank you and thanks again for this newsscript!
June 19th, 2008 at 6:58 am
Hi Sean,
First i want to thank you a lot for this great tutorial man.
Please can you answer this for :
How to implement a WYSWG. if i enter a news with paragraphs's on the page ther is nog paragraphs to see.
i want to use pagination. no i get all the articles on one page page!!
Please help.
Thx a lot.
I also want to ask when are you going to post other new tutorials i am a fun.
Thanks a lot again.
July 4th, 2008 at 11:04 am
i just want to ask something, i test the news script above, and it works pretty well but the problem is, when i upload a comment to the news script that i have upload, the error occurs saying that, "There was an error when submitting your comment, please try again". what should i do?.. can someone help me..
July 27th, 2008 at 8:11 pm
Very nice tutorial. I was wondering if someone could help me. I'm trying to implement this script with my user system. I was wondering if I could replace posting of a name with the name of the user logged in.
So instead of entering a name, it will post the users name who is logged in using $session->username;
Thanks a lot.
July 28th, 2008 at 9:49 am
Ignore my last post. I've found a solution.
August 4th, 2008 at 8:05 am
I want the news have a short story and then a link with "{read more....." so that is toggles a full story . How do i do that??.. which code doi add
October 21st, 2008 at 12:42 am
Great tut. It works perfectly!!
October 29th, 2008 at 3:04 pm
Hey, i did all of the tutorial but when i put the files to my webserver every page is blank, how should i do to actually use this news thing
December 9th, 2008 at 6:51 pm
This tutorial is one of the best I have seen regarding news systems! It's easy to modify and I put a little Wysiwyg editor into the message field so it gets even BETTER! Thanks alot mate!
December 10th, 2008 at 1:11 pm
I found out that if a ' is used in the message for adding news, the message will error and not transfer into the MySQl database (errors). When you take out all of the ', it works fine. Let me know of a workaround for this.
Thanks!
December 10th, 2008 at 1:53 pm
I corrected my issue by using:
Reference: http://us.php.net/addslashes
December 10th, 2008 at 3:53 pm
Also, I added the addslashes to comments.php for each field.
FYI
December 11th, 2008 at 8:51 am
Another issue. When using Firefox (2.0.0.18) as a browser, when you view comments.php, a scrollbar is not available to scroll through the comments. It does work in Internet Explorer. I will do some research and try to find out why. In the meantime, if anyone knows the fix, please post.
Thanks!
December 11th, 2008 at 1:39 pm
Solution to the above problem. Change the javascript line on new.php that launches comments.php to include scrollbars.
Changed line to:
Answer found at: http://www.webdevelopersnotes.com/tips/html/html_no_scrollbar_javascript_code.php3
January 24th, 2009 at 7:54 pm
hey, great tutorial overall
but i encountered a problem, i've tested the mysql_connect.php at the start and got a blank page so that's working but, whenever i manually browse to addnews.php and fill it all in, i get this error: News could not be added! Please try again.
i don't know what's wrong...
February 2nd, 2009 at 12:49 pm
Edit news works! I wanted to do exactly the same with comments but I get these messages: mysql_num_rows(): supplied argument is not a valid MySQL and mysql_fetch_array(): supplied argument is not a valid MySQL. Why and what should I write instead?
February 2nd, 2009 at 1:06 pm
I have fixed my problem now. Thank you for this great tutorial!
February 7th, 2009 at 4:45 pm
Hi all
to had a little portion of the news not the full article, then a full storry link?
any one
thanks
February 17th, 2009 at 4:34 pm
hi! I want have the 3 latest post on my index page, when a link to "news archive" there all news are and comments under! Like "commentss (3)" when you click there you see all comments! That would be awsome!
cheers
March 8th, 2009 at 4:13 am
Very good tutorial!
I have an error. I added news, but after the first one I can't add more, and for the second news in my database is all the text, but on the internet page is only the first paragraph.
Where is the problem?
Thank you.
March 8th, 2009 at 4:27 am
I forgot to tell you that I tried what you told to matt(16) to do this
ALTER TABLE news_posts CHANGE COLUMN post post MEDIUMTEXT
I tried but now I still nothing, I mean I can't add more news or to see at least all from my database.
March 8th, 2009 at 5:03 am
I don't know what was wrong with the news #2, because after I delete it everything worked fine.
One again, thank you for this great tutorial.
March 8th, 2009 at 5:56 am
Hey, A lot of people are having this problemg as well as me. For some reason when you try to post news it says "News could not be added! Please try again." I have filled in everything and I have no idear what it is? Could someone help please? Good tutorial btw exsept this minor error. Ryan
March 8th, 2009 at 12:24 pm
Something's not working...
Please check this image (I translated this script in Latvian) http://img239.imageshack.us/img239/7769/butt.jpg
Please help me :(.
And here's 1 problem too-I opened edit_news, news, mysql_connect, comments, news_manage... and there are errors too!
March 8th, 2009 at 9:53 pm
@Ryan
I had the same problem like you. I changed this
ALTER TABLE news_posts CHANGE COLUMN post post MEDIUMTEXT not null; , like the admin says in the top of the comments.
Worked to add only one news and half from the second one. After I deleted the second one worked fine for me.
March 12th, 2009 at 6:07 pm
Hey, Thanks sorin but it didnt work carrys on saying no news could not be posted
March 18th, 2009 at 11:03 am
@Ryan
Where you add news after
$message = $_POST['message'];
put
$message = mysql_real_escape_string($message);
March 24th, 2009 at 7:21 pm
Didn't know any PHP at all before, then played with the example in this tutorial. Learned a lot in one night about making databases. Thank you so much for posting this tutorial. Big step up from HTML only websites.
I had some trouble with posting special symbols for HTML, but I figured it out by browsing tutorials. Since I don't know any PHP at all, I don't know if this is the most efficient way to convert special characters to store in database, then decode it when it is retrieved from the database.
This part is in the post.php script (posting page):
$message = htmlentities($_POST['message']);
And, this part is in the news.php (display news page):
$message = html_entity_decode($_POST['message']);
Opinions?
March 24th, 2009 at 10:29 pm
Is there any way i can make it so the comments go by date?
Because at the moment they just go bellow the last post.
March 24th, 2009 at 10:36 pm
Oh uh what i mean is so they go downwards by date so the latest is at the top oldest is at the bottom.
March 25th, 2009 at 4:35 pm
Is there any reason you can think of why it would post some things and not others? For example, I could write this post (I tested it) and it would not post at all (simply give me the "news could not be posted" error) but if I wrote something like sidfjdisfnjkdgnjkdfngdjfngkdjfgnldfngkjdfgnkldjfgnkjdfngjkdfngkdjfng it would post just fine. It's really bothering me, this is the sort of thing that discourages me from using databases all together.
November 16th, 2009 at 2:47 am
Hello,
I was wondering if anybody has an in depth complete tutorial on creating a CMS, such as creating, adding deleting pages and subjects.
Any help will be much appreciated. contact is kaise@hotmail.co.uk
I have a tutorial i am working on but have got stuck as my version does not let me update the following features, page visibility it will not let me hide a page in the admin section so that it does not show on the public side and also the menu layout, it will not move a page up or dwn.
If anybody can help and have a look at my files and tell me what I am doing wrong also please.
All new to php and mysql and need urgent help plzzzzzzzz.
Regards
January 27th, 2010 at 2:54 am
[...] this is an extension for "News System with Comments". If you haven't taken the tutorial already, I seriously recommend you do because we will be using [...]