473,749 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($_SESS ION['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($qu ery, $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.h tml">Add
News</a><br />'; echo '<br><a href="logout.ph p">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_arr ay($result); echo '<br> Message: ' .
stripslashes($r ow['Message']) . '<br />'; } echo '<br><a
href="addNews.h tml">Add News</a><br />'; echo '<br><a
href="logout.ph p">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($_SESS ION['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.h tml">Return to Message</a><br />'; exit; } $news
= addslashes($new s); //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('".$news ID."','".$news. "','".$_SES SION['username']."','".$currDat e."'
)"; $result = mysql_query($ne wsQuery); 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.ph p">Logout</a><br />'; } else { echo "You are not logged
in"; } ?>

Cheers

Jan 11 '06 #1
1 2193
an***********@y ahoo.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($_SESS ION['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($qu ery, $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.h tml">Add
News</a><br />'; echo '<br><a href="logout.ph p">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_arr ay($result); echo '<br> Message: ' .
stripslashes($r ow['Message']) . '<br />'; } echo '<br><a
href="addNews.h tml">Add News</a><br />'; echo '<br><a
href="logout.ph p">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($_SESS ION['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.h tml">Return to Message</a><br />'; exit; } $news
= addslashes($new s); //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('".$news ID."','".$news. "','".$_SES SION['username']."','".$currDat e."'
)"; $result = mysql_query($ne wsQuery); 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.ph p">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="newsfunct ions.php?action =edit&id=' . $newsitem[id] .
'>Edit</a>');
echo ('<a href="newsfunct ions.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.p hp (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
2448
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 sleek Flash 7 interface. This is the first public release of FlashBB, and I've decided to make this system 100% open-source. For just $5, you get: 1) ALL of the source code, including the Flash .FLA files.
0
1819
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 done much programming with Perl or PHP. I am tempted to look for Bulletin Board software which has been written in Java. Do you know of any such products which are
7
2773
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 not allow for message posting via email. Thanks, Gerald
3
2056
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. Now I need to publish the same information on our new web site. But I don't want to put an image of the paper bulletin on the web site. I want it to look natural there, as if it were produced with god web design principles.
2
1261
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 just participate in USENET...get rewarded for it!
1
2566
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
3916
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 use to quickly set up my bulletin board? Thanks for help. Jason
0
1258
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 and age, but true. I've tried google, but the terms are just too common; all I get is clutter. So I need a python module (or snippets) that: 1. setup and execute a standard dialup with appropriate parity, stop-bits, etc 2. can emulate...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.