the code for the first page, which contains the form (and all names for the form items) is:
[php]
$type = $HTTP_GET_VARS[‘type’];
if( $type == “a” ) {
$id == $GET[‘id’];
printform( $id, $type );
} elseif( $type == “p” ) {
$id == $GET[‘id’];
printform( $id, $type );
};
function printform( $id, $type ) {
print “<form action=“process.php?id=”.$id.”&type=".$type."" method=“post” name=“comment”> n
n
Title: |
|
n
Author: |
|
n
Style: |
n
n
n
n
n
n
n
Help n
|
n
Post: |
n
|
n
|
";
};
// the code for process.php, which tries to insert the data, is this:
if ($_POST[‘post’]) {
// title of comment
$title = $_POST['title'];
// author of comment
$author = $_POST['author'];
// body text of comment
$body = "<p>".$_POST['post']."</p>";
// patterns to search for - styles
$patterns[0] = "|[b](.*?)[/b]|s";
$patterns[1] = "|[i](.*?)[/i]|s";
$patterns[2] = "|[u](.*?)[/u]|s";
$patterns[3] = "|[center](.*?)[/center]|s";
$patterns[4] = "|[link](.*?)[/link]|s";
$patterns[5] = "|[link=(.*?)](.*?)[/link]|s";
// replacements for styles
$replacements[0] = "<b>$1</b>";
$replacements[1] = "<i>$1</i>";
$replacements[2] = "<u>$1</u>";
$replacements[3] = "<center>$1</center>";
$replacements[4] = "<a href="$1">$1</a>";
$replacements[5] = "<a href="$1">$2</a>";
// sort arrays by key name
ksort($patterns);
ksort($replacements);
$replaced = preg_replace($patterns, $replacements, $body);
$type = $HTTP_GET_VARS['type'];
$entry[0] = $HTTP_GET_VARS['id'];
$entry[1] = date("dS M");
$entry[2] = stripslashes($author);
$entry[3] = stripslashes($title);
$entry[4] = stripslashes($replaced);
$entry[5] = $_SERVER['REMOTE_ADDR'];
foreach( $entry as $temp ) {
print "$temp<BR>";
};
$query = $entry[0].",null,'".$entry[1]."','".$entry[2]."','".$entry[3]."','".$entry[4]."','".$entry[5]."'";
$user = "time2ch_conn";
$password = "***";
$conn = mysql_connect( "localhost", $user, $password );
mysql_select_db( "time2ch_comments" );
if( $type = "a" ) {
mysql_query( "LOCK TABLES article WRITE" ) or die( "Couldn't LOCK: ".mysql_error() );
mysql_query( "INSERT INTO article VALUES ".$query ) or die( "Couldn't INSERT: ".mysql_error() );
mysql_query( "UNLOCK TABLES" ) or die( "Couldn't UNLOCK: ".mysql_error() );
mysql_close( $conn );
header( "Location: http://www.time2changefbcy.com/index.ph ... rticle&id=".$id );
} elseif( $type = "p" ) {
mysql_query( "LOCK TABLES poll WRITE" ) or die( "Couldn't LOCK: ".mysql_error() );
mysql_query( "INSERT INTO poll VALUES ".$poll ) or die( "Couldn't INSERT: ".mysql_error() );
mysql_query( "UNLOCK TABLES" ) or die( "Couldn't UNLOCK: ".mysql_error() );
mysql_close( $conn );
header( "Location: http://www.time2changefbcy.com" );
};
};
[/php]
MOD EDIT: Added PHP bb code tags
also, the table in mysql (at least for the articles, the poll table is a bit modified) has these columns (in order)
id (int 6) [this is the id of the article. in the comment.php GET line, this is “id”
commentid (int 6) auto increment primary key
date (varchar 10) [generated using Date() function - text date]
author (varchar 35) [author’s name]
title (varchar 35) [title of post]
post (text) [text of post]
ip (varch 15) [ip of poster, found with remote address thingy]
the poll comments table is modified slightly so that id is an int 4.
thanks!