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

doInsert() Function - 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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The last of our three functions is the doInsert() function, which is given the task of inserting a tag into the database, returning the result of the insert, and then refreshing only the page in the Inline Frame to display all tags, which will hopefully include the tag the user just submitted.

The code we used to achieve this is detailed below:

function doInsert($__name, $__entry, $__url)
{
$conx = mysql_connect(HOST, USER, PASS) or die("Unable to connect to MySQL Server");
mysql_select_db(DB) or die("Unable to select Database");

$__name = addslashes($__name);
$__url = addslashes($__url);
$__entry = addslashes($__entry);

if (empty($__name))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Name Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} elseif (empty($__entry))
{
?>
<p style="font-family: verdana,arial,helvetica,sans-serif; font-size: 11px; background-color: #FFFFFF">Entry Field Is Required</p>
<meta http-equiv="refresh" content="5;url='board.php?do=Tags'">
<?
} else {
$stSql = "INSERT INTO tagboard(tagId, tag_name, tag_url, tag_entry, tag_date) values('', '$__name', '$__url', '$__entry', ".time().")";
$arrResult = @mysql_query($stSql);
if (!$arrResult) { echo "Query Failed - Unable to Retrieve tags - ".mysql_error()." - Line: __LINE__"; exit(); }

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'">
<?
}
}
}

As you can see in this first part of our function, we connect to our MySQL database and then select the database we will be using, which as I mentioned earlier in the article uses our defined constants.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: