HomePHP 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.
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:
} }
Conclusion
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.