Database Code
  Home arrow Database Code arrow PHP & MySQL Tagboard
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

PHP & MySQL Tagboard
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2002-05-27

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    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!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    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!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    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!


    NEW! Test terminal-based applications with Rational Functional Tester

    Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Webcast: WebSphere Process Server

    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!

    DATABASE CODE ARTICLES

    - Examples and Tools for Database Design
    - Relationships, Entities and Database Design
    - Modeling and Designing Databases
    - Data extract to Excel
    - Oracle database class 0.76
    - The opposite of mysql_fetch_assoc
    - On line Thermal Transmitance Calculation
    - pjjTextBase
    - PHP Object Generator
    - FastMySQL
    - RC4PHP
    - SQL function with integrated sprintf()
    - DB Interaction Classes v1.1
    - deeMySQLParser
    - CSV to SQL convertor





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek