473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

PHP news bulletin site

Hi guys,

having a little trouble working out how i'm going to do this. At the
moment, users can log in and click a link to add news. This opens a
page to enter the message and submit it to the database. These are then
shown on the homepage.

Questions are how can i go about letting the users edit or delete the
messages? I think i need to add a link to the messages with the newsID
that the users can then click to select that message. They can then be
given a button to delete or edit it.

So how do i add a link to the messages that will contain that messages
ID so i can reload it?

Sorry if its a little confusing, tired now.

Cheers for any help.

Heres what i have so far, this is the index page that is displayed with
the messages on.

Code:

<?php session_start(); if(isset($_SESSION['username'])){ echo "Welcome
".$_SESSION['username']. '<br />'; //connect to mysql @ $db =
mysql_pconnect('localhost', 'root', 'chase'); if(!$db){ echo 'Error:
Could not connect to the database.'; } //connect to database
mysql_select_db('dbHelpdesk'); $query = "select * from news"; $result =
mysql_query($query, $db); $num_results = mysql_num_rows($result);
$_SESSION['numNews']=$num_results; if($num_results == 0 ){ echo 'There
are no current news items.'; echo '<br><a href="addNews.html">Add
News</a><br />'; echo '<br><a href="logout.php">Logout</a><br />';
exit; }else echo '<br> Number of News Items ' . $num_results . '<br
/>'; //get news items for ($a=0; $a < $num_results; $a++){ $row =
mysql_fetch_array($result); echo '<br> Message: ' .
stripslashes($row['Message']) . '<br />'; } echo '<br><a
href="addNews.html">Add News</a><br />'; echo '<br><a
href="logout.php">Logout</a><br />'; } else { echo "You are not logged
in"; } ?>

Next we have the page where i'm adding the messages.

Code:

<?php session_start(); if(isset($_SESSION['username'])){ $news =
$HTTP_POST_VARS['message']; //echo '<br>' . $news . '<br />';
if(!$news){ echo 'Please make sure you fill in the message box.'; echo
'<br><a href="addNews.html">Return to Message</a><br />'; exit; } $news
= addslashes($news); //connect to the db to post news @ $db =
mysql_pconnect('localhost', 'root','chase'); if(!$db){ echo 'Error:
Could not connect to the database.'; exit; }
mysql_select_db('dbHelpdesk'); $newsID = $_SESSION['numNews'] + 1 ;
$currDate = date('Y-m-d'); $newsQuery = "insert into news
values('".$newsID."','".$news."','".$_SESSION['username']."','".$currDate."'
)"; $result = mysql_query($newsQuery); if ($result){ echo
mysql_affected_rows() . ' news item added to database'; } echo '<br><a
href="index.php">Return to Main Page</a><br />'; echo '<br><a
href="logout.php">Logout</a><br />'; } else { echo "You are not logged
in"; } ?>

Cheers

Jan 11 '06 #1
1 2166
an***********@yahoo.co.uk wrote:
Hi guys,

having a little trouble working out how i'm going to do this. At the
moment, users can log in and click a link to add news. This opens a
page to enter the message and submit it to the database. These are then
shown on the homepage.

Questions are how can i go about letting the users edit or delete the
messages? I think i need to add a link to the messages with the newsID
that the users can then click to select that message. They can then be
given a button to delete or edit it.

So how do i add a link to the messages that will contain that messages
ID so i can reload it?

Sorry if its a little confusing, tired now.

Cheers for any help.

Heres what i have so far, this is the index page that is displayed with
the messages on.

Code:

<?php session_start(); if(isset($_SESSION['username'])){ echo "Welcome
".$_SESSION['username']. '<br />'; //connect to mysql @ $db =
mysql_pconnect('localhost', 'root', 'chase'); if(!$db){ echo 'Error:
Could not connect to the database.'; } //connect to database
mysql_select_db('dbHelpdesk'); $query = "select * from news"; $result =
mysql_query($query, $db); $num_results = mysql_num_rows($result);
$_SESSION['numNews']=$num_results; if($num_results == 0 ){ echo 'There
are no current news items.'; echo '<br><a href="addNews.html">Add
News</a><br />'; echo '<br><a href="logout.php">Logout</a><br />';
exit; }else echo '<br> Number of News Items ' . $num_results . '<br
/>'; //get news items for ($a=0; $a < $num_results; $a++){ $row =
mysql_fetch_array($result); echo '<br> Message: ' .
stripslashes($row['Message']) . '<br />'; } echo '<br><a
href="addNews.html">Add News</a><br />'; echo '<br><a
href="logout.php">Logout</a><br />'; } else { echo "You are not logged
in"; } ?>

Next we have the page where i'm adding the messages.

Code:

<?php session_start(); if(isset($_SESSION['username'])){ $news =
$HTTP_POST_VARS['message']; //echo '<br>' . $news . '<br />';
if(!$news){ echo 'Please make sure you fill in the message box.'; echo
'<br><a href="addNews.html">Return to Message</a><br />'; exit; } $news
= addslashes($news); //connect to the db to post news @ $db =
mysql_pconnect('localhost', 'root','chase'); if(!$db){ echo 'Error:
Could not connect to the database.'; exit; }
mysql_select_db('dbHelpdesk'); $newsID = $_SESSION['numNews'] + 1 ;
$currDate = date('Y-m-d'); $newsQuery = "insert into news
values('".$newsID."','".$news."','".$_SESSION['username']."','".$currDate."'
)"; $result = mysql_query($newsQuery); if ($result){ echo
mysql_affected_rows() . ' news item added to database'; } echo '<br><a
href="index.php">Return to Main Page</a><br />'; echo '<br><a
href="logout.php">Logout</a><br />'; } else { echo "You are not logged
in"; } ?>

Cheers


Add another field to your news table in the database called id. You can
then either have it auto-increment or you can set it yourself -
auto-increment is the preferred way, since you do not have to worry
about what it is. When you fetch the news items, output the contents of
the id field into your output, say like:

echo $newsitem[text];
echo ('<a href="newsfunctions.php?action=edit&id=' . $newsitem[id] .
'>Edit</a>');
echo ('<a href="newsfunctions.php?action=delete&id=' . $newsitem[id] .
'>Delete</a>');

This codes the news item's id into the link for you when it puts it on
the page. On your newsfunctions.php (in the example), you would use:

$the_action = $_GET['action'];
$the_id = $_GET['id'];

And then use your sql functions to determine which news item you are
operating on:

if $the_action = 'edit'
{
$sql = ('select * from news where id = ' . $the_id);
// run the sql and drop results in an array, edit the text
// field and put back in the database

} else if $the_action = 'delete' {
$sql = ('select * from news where id = ' . $the_id);
// run the sql and drop results into an array, ask the user
// if they are sure they want to delete, and remove the row
// from the database. drop it to an array so you can show
// the entry or even a preview of it so they know it's the
// right one :)

} else {
echo ('invalid function');
// or whatnot
}

Hope that helps you out some. It's what I do, and would do in your case.

-John D. Mann
Jan 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: g8z | last post by:
Greetings! It is with great pride that I announce the release of FlashBB, the newest member of the TUFaT.com family of products! FlashBB is a PHP / MySQL - driven bulletin board, sporting a...
0
by: Mukesh Kumar | last post by:
Dear friends, I am very new to this forum. Please pardon me if this question has been posted before. I am looking for some Bulletin Board software like UBB, YaBB etc. I know Java but haven't...
7
by: Gerald S | last post by:
Hello All, I am looking for an asp-based bulletin board forum where users can post via email or the standard web interface. Similar to Yahoo Groups. I have looked an my asp forums, but most do...
3
by: Tim Dempsey | last post by:
Folks, I need some advice. I hpoe some of you can advise me. Our church's weekly bulletin has been published on paper for years. It is created in MS Word and sent to the publishing company....
2
by: Patrick Olurotimi Ige | last post by:
Hi All, Can anybody forward me a free Bulletin/Message Board built with ASP.NET! Any other resources would be appreciated... *** Sent via Developersdex http://www.developersdex.com *** Don't...
1
by: qwe85 | last post by:
Hi, Can anyone teach me how to create a bulletin board using ASP.NET? I would greatly appreciate your help. Thank you in advance --
3
by: Jason Huang | last post by:
Hi, I would like to build up a web bulletin board by using C#. But my schedule is quite busy, and I'm not familiar with the C# web form. So, I'm thinking is there any C# based free ware I can...
0
by: Sells, Fred | last post by:
We need to automate the download of data that is now done manually via a terminal session to a dialup bulletin board. The user uses this to upload and download files. Hard to believe in this day...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.