A simple yet efficient tagboard written in PHP with a MySQL back-end.
By : ipx
HTML for tagboard:
<iframe src='view.php' border='0' name='tagboard'></iframe><br>
<form action='post.php' method='post' target='tagboard'>
<input type='text' name='name' value='name'><br>
<input type='text' name='http' value='http://'><br>
<input type='text' name='msg' value='message'><br>
<input type='submit' value='Submit'> <input type='reset' value='Reset'>
</form>
--post.php--
<?php
#change localhost to the sql server, user to the correct username, and pass to the correct password
$con = mysql_connect("localhost","user","pass") or die("Unable to establish a connection to the database.");
#change database to the database name
$database = "database";
$db = mysql_select_db("$database") or die("Couldn't select database $database.");
#lets strip some chars and slashes
$name = stripslashes($name);
$name = htmlspecialchars($name);
$http = stripslashes($http);
$http = htmlspecialchars($http);
$msg = stripslashes($msg);
$msg = htmlspecialchars($msg);
$query = "INSERT INTO tagboard(name,http,msg)
VALUES('$name,$http,$msg')";
$result = mysql_query($query) or die("Data couldn't be entered into the database.");
echo "Click <a href='view.php'>here</a>.";
?>
--view.php--
<?php
#change localhost to the sql server, user to the correct username, and pass to the correct password
$con = mysql_connect("localhost","user","pass") or die("Unable to establish a connection to the database.");
#change database to the database name
$database = "database";
$db = mysql_select_db("$database") or die("Couldn't select database $database.");
$query = "SELECT id,name,http,msg FROM tagboard ORDER BY id DESC"; selects all the rows from the table tagboard and orders them in descending order
$result = mysql_query($query);
while ($rows = mysql_fetch_row($result))//a loop
{
echo "<a href='$row[http]' target='_blank'>$row[name]</a>: $row[msg]<br>";
}
?>
--admin.php--
<?php
/*$PHP_AUTH_USER != 'user' is the username setting & $PHP_AUTH=PW !='open' is the password setting*/
if ( ( !isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))
|| ( $PHP_AUTH_USER != 'user' ) || ( $PHP_AUTH_PW != 'open' ) ) {
//name of the realm or protected area.
header( 'WWW-Authenticate: Basic realm="Tagboard Administration"' );
header( 'HTTP/1.0 401 Unauthorized' );
/*when authorization fails*/
echo "Authorization Required.";
exit;
}
else {
/*Function used to connect to sql server and choose database*/
function connect(){
#change localhost to the sql server, user to the correct username, and pass to the correct password
$con = mysql_connect("localhost","user","pass") or die("Unable to establish a connection to the database.");
#change database to the database name
$database = "database";
$db = mysql_select_db("$database") or die("Couldn't select database $database.");
}
echo "Tagboard Administration <br> <a href='admin.php?action=view'>View messages
</a> <a href='admin.php?action=delall'>Delete all messages</a> <a href='admin.php?action=update'><br><br>";
if($action == "view"){
connect();
$query = "SELECT id,name,http,msg FROM tagboard ORDER BY id DESC";
$result = mysql_query($query);
while ($rows = mysql_fetch_row($result)){
echo "<a href='$row[http]' target='_blank'>$row[name]</a>: $row[msg] : <a href='admin.php?action=del&id=$row[id]'>Delete</a><br>";
}
}
if($action == "del"){
connect();
$query = "DELETE FROM tagboard WHERE id='$id'";
$result = mysql_query($query);
}
if($action == "delall"){
connect();
$query = "DELETE FROM tagboard";
$result = mysql_query($query);
}
if($action == "update"){
connect();
$query = "SELECT id,name,http,msg FROM tagboard ORDER BY id DESC";
$result = mysql_query($query);
while ($rows = mysql_fetch_row($result)){
echo "<a href='$row[http]' target='_blank'>$row[name]</a>: $row[msg] : ID#: $row[id]<br>";
}
echo "<br>
<form action='admin.php?action=update&go=yes' method='post'>
<input type='text' name='id' value='ID #'><br>
<input type='text' name='name' value='Name'><br>
<input type='text' name='http' value='http://'><br>
<textarea name='msg'>Message</textarea><br>
<input type='submit' value='Submit'> <input type='reset' value='Reset'>
</form>";
}
if($go == "yes"){
connect();
$id = stripslashes($id);
$id = htmlspecialchars($id);
$name = stripslashes($name);
$name = htmlspecialchars($name);
$http = stripslashes($http);
$http = htmlspecialchars($http);
$msg = stripslashes($msg);
$msg = htmlspecialchars($msg);
$query = "UPDATE tagbard WHERE id='$id' SET name='$name' http='$http' msg='$msg'";
$result = mysql_query($query);
echo "ID # $id has been edited successfully.";
}
}
?>
--sql syntax--
CREATE TABLE tagboard (id TINYINT (4) not null AUTO_INCREMENT, name VARCHAR (32), msg VARCHAR (50), http VARCHAR (32) , PRIMARY KEY (id))
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
|
|
|
|
The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |