|
Posted by andyt_2000_uk@yahoo.co.uk on 01/11/06 03:10
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
[Back to original message]
|