Jump to content

How to post announcements to website


robmo

Recommended Posts

Hi,

 

I need to provide the ability for a user to login and post announcements. I have done some searching and haven't really came up with anything that will work so far. I would like to use a script that is external to the web page that will display the message. If that is not best practice, please let me know.

 

My idea was to create a Div that contains a multi-line text box within it and perhaps post the announcement there. I am curious if it would be a good idea to include a database for this task. The announcements will likely be posted by only one user and they will be very infrequent so maybe a text file would suffice.

 

Is this a good approach or is there a better way? I'm not really asking anyone to code this for me but some suggestions for achieving this task would be greatly appreciated. I am trying to move away from using a CMS for this particular site. I have been told that javascript is the wrong approach to this solution and would need to use server-side scripting. PHP was called out for this project.

 

Thanks for your help!

Rob

Link to comment
Share on other sites

A form would work but I wouldn't want the form to be exposed until a user has authenticated to prevent just anyone from posting. The announcements will be posted on the home page of the site and I thought I would place a Div to reserve the space so I don't have to deal with rearranging content when there are no active announcements. I would just leave the "announcement Div" in place at all times.

 

Does that help? Let me know if you need more detail.

Link to comment
Share on other sites

You could create a login form that will check your db for user then creates an auth cookie. You then can check the cookie exists as to whether or not to display certain parts of pages.

 

eg:

$sql = "select * from tbl_users where username=\"$username\" and password=\"$password\"";
$rs = mysql_query( $sql, $conn )or die( "Error Query" );

		#search for matches		
		$num = mysql_num_rows ($rs);
		if ($num !=0)
		{
			setcookie("auth", "ok");
			header("Location:index.php");

		}
		else
		{
		echo("Invalid Login");
		}

 

Then check for it to display:

 

$auth = $_COOKIE['auth'];

if ( $auth == 'ok' )
{
#form code
}
else
{
echo ("You need to be logged in to submit");
}

 

obviously this is simple terms but may get you started.

Link to comment
Share on other sites

I noticed that there many examples of this on the web. I will be working on that the next few days. I'm thinking it would be a good idea to store the announcements in a database since i have to make one anyway. I just need to figure out how i get the data/announcements from the database to an area on the home page. Lots of fun!

Link to comment
Share on other sites

$sql = "SELECT * FROM tbl_announcements";
$rs = mysql_query( $sql, $conn )
	or die( "Error Query");

$list = "<table border=\"1\" cellpadding=\"2\" align=\"center\" width=\"98%\">";	
$list .= "<tr>";
$list .= "<td colspan=\"3\"><h1>Announcements</h1></td>";
$list .= "</tr>";	
$list .= "<tr>";
while($row = mysql_fetch_array( $rs ))
{	
$list .= "<td width=\"33%\">".  rtrim(nl2br($row['announc'])) ."<br><br>Submitted by: ". rtrim($row['username']) ."</td>";
}	
$list .= "</tr>";
$list .= "</table><br>";
$list .= "<table border=\"0\" cellpadding=\"2\" align=\"center\" width=\"98%\">";	
$list .= "<tr>";
$list .= "<td><h1>Submit your \"Announcement???\" *</h1></td>";
$list .= "</tr>";
if ( $auth != 'ok' )
{	
$list .= "<tr>";
$list .= "<td  width=\"50%\">Sorry, you need to <a href=\"../login_form.php\">LOGIN</a> to submit an announcement???</td>";
$list .= "</tr>";
}
else
{
$list .= "<tr>";
$list .= "<td>My \"Anouncement\":<br><textarea rows=\"5\" cols=\"40\" id=\"announc\" name=\"announc\"></textarea></td>";
$list .= "<td rowspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Submit\" class=\"submit\"></form>";
$list .= "</tr>";
}
$list .= "</table>";
echo( $list );

 

quickly knocked up so syntax and layout may be a bit off

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.