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!
|
|
|
|
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
|
|
|
|
In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |