robmo Posted October 12, 2010 Share Posted October 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
New Coder Posted October 12, 2010 Share Posted October 12, 2010 do you mean an input form with free text boxes where a user can fill in and save then it displays on the submitted items page? Quote Link to comment Share on other sites More sharing options...
robmo Posted October 12, 2010 Author Share Posted October 12, 2010 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. Quote Link to comment Share on other sites More sharing options...
robmo Posted October 12, 2010 Author Share Posted October 12, 2010 Does anyone know how to go about accomplishing this? Quote Link to comment Share on other sites More sharing options...
New Coder Posted October 13, 2010 Share Posted October 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
robmo Posted October 13, 2010 Author Share Posted October 13, 2010 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! Quote Link to comment Share on other sites More sharing options...
New Coder Posted October 13, 2010 Share Posted October 13, 2010 $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 Quote Link to comment Share on other sites More sharing options...
robmo Posted October 13, 2010 Author Share Posted October 13, 2010 I also got a suggesting to use a PHP News solution. That looks like it might work but I want to look at your solution as well. Now to get my hands dirty! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.