Home arrow PHP arrow Page 11 - Building a Quick and Easy Tag Board

Inserting into the Tag Board - PHP

Tag boards enable users to leave a short message on your site without having to go through the trouble of registering. From a development point of view, they are actually rather simple to develop. In this article we will create a quick and easy tag board for any web site. We will be taking advantage of the php and MySQL technologies.

  1. Building a Quick and Easy Tag Board
  2. Did Anyone Say MySQL?
  3. Our Tag Board Script
  4. What Makes Our Tag Board Tick?
  5. Our Tag Board Functions!
  6. Retrieval and Sorting of Tags
  7. Results
  8. doBoard() Function
  9. doInsert() Function
  10. Ensuring Data Submitted Does Not Fail
  11. Inserting into the Tag Board
By: Haiden Taylor
Rating: starstarstarstarstar / 120
November 03, 2004

print this article



The first and most significant is the SQL query we have used to insert the information into the database. That code is below:

$stSql = "INSERT INTO tagboard(tagId, tag_name, tag_url, tag_entry, tag_date) values('', '$__name', '$__url', '$__entry', ".time().")";

As you can see, we are Inserting Into our table “tagboard” into the following fields “(tagId, tag_name, tag_url, tag_entry, tag_date)”. We wish to place the following values, in order of how they appear, “values('', '$__name', '$__url', '$__entry', ".time().")";”. As you may have noticed we left the value which corresponds with tagId empty (‘’). We did this because as mentioned earlier the tagId field is auto increment, meaning if we leave the value empty, the next Id in line will be automatically assigned. We also used the php time() function for the tag_date field; this was explained in the “Did Anyone Say MySQL” section earlier in the article.

Next we check to see if our MySQL query was executed successfully. Since we covered this section in the doTags() function, we will move along to our if statement. This code is detailed below:

if (mysql_affected_rows() == 1)
<meta http-equiv="refresh" content="3;url='board.php?do=Tags'">
} else {
echo "Unable to Add Entry to Database";
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">

In this snippet we check to see if any MySQL rows were affected, which if the insert was successful, we simply refresh the Inline Frame to display the doTags() function and the user will see their tag. If the query failed will inform the user, then refresh the Inline Frame back to the doTags() function. We then close our elseif statement and close our function. Displayed below:



As you can see it is possible to create a Tag Board for your site and have it running out of one php script. We have achieved all our requirements with three functions.

If you followed this article correctly, you should have a tag board of your own ready to go on your site. You should also have the knowledge of how to Insert and retrieve data from a MySQL database.

>>> More PHP Articles          >>> More By Haiden Taylor

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: