messageboy
New Member
- Messages
- 12
- Reaction score
- 0
- Points
- 0
This one is quite a hard problem so thanks to all in advance who try to help.
I working on a forums which it very basic at the moment and requires users to enter a title, text, name, email and etc.
I can get rid of the name input so it doesn't have them input one but I want to put their member username in that place to be uploaded into the database.
<?php
class SForum {
var $SFname = "SForum";
var $ptitle;
var $react; // number of answers in a thread
var $pansw;
var $title;
// SForum: constructor, connecting to DB
function SForum() {
$this->ptitle = NULL;
$this->pansw = 0;
$this->title = "<TITLE>$this->SFname</TITLE>";
print($this->title);
include_once("config.php"); // DB Config Data
$pol = mysql_connect($dbhost,$dbuname,$dbpass) or die ("Couldn't connect to server.<br>\n");
$db = mysql_select_db($dbname,$pol) or die ("Couldn't connect to database.<br>\n");
}
// Show_frm: displays the form
function Show_frm($ptitle=NULL) {
if(!empty($ptitle)) {
$this->ptitle = "Re: ".$ptitle;
}
$zawartosc = "\n\n<FORM ACTION=\"".$_SERVER['PHP_SELF']."\" METHOD=\"post\" NAME=\"frm\">\n"
. "<TABLE><TR>\n"
. "<TD>Title:</TD><TD><INPUT TYPE=\"text\" NAME=\"frm_ptitle\" VALUE=\"$this->ptitle\" SIZE=\"65\"></TD>\n"
. "</TR><TR>\n"
. "<TD>Text:</TD><TD><TEXTAREA NAME=\"frm_text\" cols=\"50\" rows=\"10\"></TEXTAREA></TD>\n"
. "</TR><TR>\n"
. "<TD>Name or nick:</TD><TD><INPUT TYPE=\"text\" NAME=\"frm_name\" VALUE=\"\" SIZE=\"25\"></TD>\n"
. "</TR><TR>\n"
. "<TD COLLSPAN=\"2\"><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Post\"></TD>\n"
. "</tr></TABLE>\n"
. "<INPUT TYPE=\"hidden\" NAME=\"frm_ip\" VALUE=\"".$_SERVER['REMOTE_ADDR']."\">\n"
. "<INPUT TYPE=\"hidden\" NAME=\"frm_wid\" VALUE=\"".$this->pansw."\">\n"
. "</FORM>\n\n";
print($zawartosc);
}
// Show_SFname : Show SForum name as text
function Show_SFname() {
print("<H1>$this->SFname</H1>\n");
}
// Add_new_post: Adds new record to DB
function Add_new_post($ptitle,$text,$ip,$frm_wid) {
if($ptitle=="" or $text==""){
return;
}
$this->ptitle = addslashes(htmlspecialchars(trim($ptitle)));
$this->text = addslashes(htmlspecialchars(trim($text)));
if ($frm_wid == 0) {
$zapytanie = "INSERT INTO SForum (wid,for_ptitle,for_text,for_mail,for_data,for_dataw,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(), now(), '$ip', '$name')";
$sql = mysql_query($zapytanie) or die (mysql_error());
} else {
$zapytanie = "INSERT INTO SForum (wid,for_ptitle,for_text,for_mail,for_data,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(), '$ip', '$name')";
$sql = mysql_query($zapytanie) or die (mysql_error());
}
$id = mysql_insert_id();
if ($frm_wid == 0) {
$zapytanie = "UPDATE SForum SET wid='$id' WHERE id='$id'";
#print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
} else {
$zapytanie = "UPDATE SForum SET for_dataw=now() WHERE id='$frm_wid'";
#print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
}
}
// Show_SForum: Displays the main message of threads
function Show_SForum() {
$sql = 'SELECT * FROM SForum WHERE id=wid ORDER BY for_dataw DESC';
#print $sql."<br>\n";
$sql = mysql_query($sql) or die (mysql_error());
$iledokumentow = mysql_affected_rows();
if ($iledokumentow > 0) {
print("<TABLE BORDER=\"1\" WIDTH=\"90%\">\n");
while ($row = mysql_fetch_array($sql)) {
$sql1 = "SELECT COUNT(wid)-1 AS num FROM SForum WHERE wid=".$row['id']." GROUP BY wid";
#print $sql1."<br>\n";
$sql1 = mysql_query($sql1) or die (mysql_error());
$row1 = mysql_fetch_array($sql1);
//number of reactions
$this->react=$row1['num'];
if ($row['for_name'] == "") {
$row['for_name'] = "Error";
}
$this->ptitle = stripslashes($row['for_ptitle']);
print("<tr><TD width=30%><A HREF=\"".$_SERVER['PHP_SELF']."?wid=".$row['id']."\">".$this->ptitle."</A></TD><TD ALIGN=\"center\" width=10%>Replies: ".$this->react."</TD><TD ALIGN=\"center\" WIDTH=\"10%\">".$row['for_name']."</TD><TD ALIGN=\"center\" WIDTH=\"20%\">".$row['for_dataw']."</TD></tr>\n\n");
}
unset($this->react);
print("</TABLE>\n");
} else {
print("No threads<br>\n");
}
$this->ptitle = ""; //the new thread's title is empty
}
// Show_SForum_Threads: Displays all messages of a thread
function Show_SForum_Threads($wid) {
//$this->pansw = $wid;
$zapytanie = "SELECT * FROM SForum WHERE wid='$wid' ORDER BY for_data ASC";
//print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
$iledokumentow = mysql_affected_rows();
if ($iledokumentow > 0) {
print("<TABLE BORDER=\"1\" WIDTH=\"90%\">\n");
while ($row = mysql_fetch_array($sql)) {
$this->ptitle = stripslashes($row['for_ptitle']);
$this->text = nl2br(stripslashes($row['for_text']));
if ($row['for_name'] == "") {
$row['for_name'] = "Error";
}
if ($row['for_mail'] !== "") {
$pmail = "<A HREF=\"mailto:".$row['for_mail']."\">";
$kmail = "</a>";
} else {
$pmail = NULL;
$kmail = NULL;
}
print("<tr><TD><b>".$this->ptitle."</b><br><div ALIGN=\"right\"><i><U>$pmail".$row['for_name']."$kmail</u> <FONT SIZE=\"1\">".$row['for_data']."</FONT></i></DIV>\n\n");
print("<hr>".$this->text."<br><br></TD></tr>\n\n");
}
print("</TABLE>\n");
} else {
print("No threads<br>\n");
}
$zapytanie = "SELECT * FROM SForum WHERE id='$wid' LIMIT 0,1";
$sql = mysql_query($zapytanie) or die (mysql_error());
$row = mysql_fetch_array($sql);
$this->ptitle = stripslashes($row['for_ptitle']); //Re title for form
}
// Main_page: Show back-to-main link
function Main_page() {
print("<A HREF=\"".$_SERVER['PHP_SELF']."\">Go to Main Page</A>\n");
}
}
if (!isset($forum)) {
$forum = new SForum;
}
?>
I working on a forums which it very basic at the moment and requires users to enter a title, text, name, email and etc.
I can get rid of the name input so it doesn't have them input one but I want to put their member username in that place to be uploaded into the database.
<?php
class SForum {
var $SFname = "SForum";
var $ptitle;
var $react; // number of answers in a thread
var $pansw;
var $title;
// SForum: constructor, connecting to DB
function SForum() {
$this->ptitle = NULL;
$this->pansw = 0;
$this->title = "<TITLE>$this->SFname</TITLE>";
print($this->title);
include_once("config.php"); // DB Config Data
$pol = mysql_connect($dbhost,$dbuname,$dbpass) or die ("Couldn't connect to server.<br>\n");
$db = mysql_select_db($dbname,$pol) or die ("Couldn't connect to database.<br>\n");
}
// Show_frm: displays the form
function Show_frm($ptitle=NULL) {
if(!empty($ptitle)) {
$this->ptitle = "Re: ".$ptitle;
}
$zawartosc = "\n\n<FORM ACTION=\"".$_SERVER['PHP_SELF']."\" METHOD=\"post\" NAME=\"frm\">\n"
. "<TABLE><TR>\n"
. "<TD>Title:</TD><TD><INPUT TYPE=\"text\" NAME=\"frm_ptitle\" VALUE=\"$this->ptitle\" SIZE=\"65\"></TD>\n"
. "</TR><TR>\n"
. "<TD>Text:</TD><TD><TEXTAREA NAME=\"frm_text\" cols=\"50\" rows=\"10\"></TEXTAREA></TD>\n"
. "</TR><TR>\n"
. "<TD>Name or nick:</TD><TD><INPUT TYPE=\"text\" NAME=\"frm_name\" VALUE=\"\" SIZE=\"25\"></TD>\n"
. "</TR><TR>\n"
. "<TD COLLSPAN=\"2\"><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Post\"></TD>\n"
. "</tr></TABLE>\n"
. "<INPUT TYPE=\"hidden\" NAME=\"frm_ip\" VALUE=\"".$_SERVER['REMOTE_ADDR']."\">\n"
. "<INPUT TYPE=\"hidden\" NAME=\"frm_wid\" VALUE=\"".$this->pansw."\">\n"
. "</FORM>\n\n";
print($zawartosc);
}
// Show_SFname : Show SForum name as text
function Show_SFname() {
print("<H1>$this->SFname</H1>\n");
}
// Add_new_post: Adds new record to DB
function Add_new_post($ptitle,$text,$ip,$frm_wid) {
if($ptitle=="" or $text==""){
return;
}
$this->ptitle = addslashes(htmlspecialchars(trim($ptitle)));
$this->text = addslashes(htmlspecialchars(trim($text)));
if ($frm_wid == 0) {
$zapytanie = "INSERT INTO SForum (wid,for_ptitle,for_text,for_mail,for_data,for_dataw,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(), now(), '$ip', '$name')";
$sql = mysql_query($zapytanie) or die (mysql_error());
} else {
$zapytanie = "INSERT INTO SForum (wid,for_ptitle,for_text,for_mail,for_data,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$mail', now(), '$ip', '$name')";
$sql = mysql_query($zapytanie) or die (mysql_error());
}
$id = mysql_insert_id();
if ($frm_wid == 0) {
$zapytanie = "UPDATE SForum SET wid='$id' WHERE id='$id'";
#print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
} else {
$zapytanie = "UPDATE SForum SET for_dataw=now() WHERE id='$frm_wid'";
#print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
}
}
// Show_SForum: Displays the main message of threads
function Show_SForum() {
$sql = 'SELECT * FROM SForum WHERE id=wid ORDER BY for_dataw DESC';
#print $sql."<br>\n";
$sql = mysql_query($sql) or die (mysql_error());
$iledokumentow = mysql_affected_rows();
if ($iledokumentow > 0) {
print("<TABLE BORDER=\"1\" WIDTH=\"90%\">\n");
while ($row = mysql_fetch_array($sql)) {
$sql1 = "SELECT COUNT(wid)-1 AS num FROM SForum WHERE wid=".$row['id']." GROUP BY wid";
#print $sql1."<br>\n";
$sql1 = mysql_query($sql1) or die (mysql_error());
$row1 = mysql_fetch_array($sql1);
//number of reactions
$this->react=$row1['num'];
if ($row['for_name'] == "") {
$row['for_name'] = "Error";
}
$this->ptitle = stripslashes($row['for_ptitle']);
print("<tr><TD width=30%><A HREF=\"".$_SERVER['PHP_SELF']."?wid=".$row['id']."\">".$this->ptitle."</A></TD><TD ALIGN=\"center\" width=10%>Replies: ".$this->react."</TD><TD ALIGN=\"center\" WIDTH=\"10%\">".$row['for_name']."</TD><TD ALIGN=\"center\" WIDTH=\"20%\">".$row['for_dataw']."</TD></tr>\n\n");
}
unset($this->react);
print("</TABLE>\n");
} else {
print("No threads<br>\n");
}
$this->ptitle = ""; //the new thread's title is empty
}
// Show_SForum_Threads: Displays all messages of a thread
function Show_SForum_Threads($wid) {
//$this->pansw = $wid;
$zapytanie = "SELECT * FROM SForum WHERE wid='$wid' ORDER BY for_data ASC";
//print $zapytanie;
$sql = mysql_query($zapytanie) or die (mysql_error());
$iledokumentow = mysql_affected_rows();
if ($iledokumentow > 0) {
print("<TABLE BORDER=\"1\" WIDTH=\"90%\">\n");
while ($row = mysql_fetch_array($sql)) {
$this->ptitle = stripslashes($row['for_ptitle']);
$this->text = nl2br(stripslashes($row['for_text']));
if ($row['for_name'] == "") {
$row['for_name'] = "Error";
}
if ($row['for_mail'] !== "") {
$pmail = "<A HREF=\"mailto:".$row['for_mail']."\">";
$kmail = "</a>";
} else {
$pmail = NULL;
$kmail = NULL;
}
print("<tr><TD><b>".$this->ptitle."</b><br><div ALIGN=\"right\"><i><U>$pmail".$row['for_name']."$kmail</u> <FONT SIZE=\"1\">".$row['for_data']."</FONT></i></DIV>\n\n");
print("<hr>".$this->text."<br><br></TD></tr>\n\n");
}
print("</TABLE>\n");
} else {
print("No threads<br>\n");
}
$zapytanie = "SELECT * FROM SForum WHERE id='$wid' LIMIT 0,1";
$sql = mysql_query($zapytanie) or die (mysql_error());
$row = mysql_fetch_array($sql);
$this->ptitle = stripslashes($row['for_ptitle']); //Re title for form
}
// Main_page: Show back-to-main link
function Main_page() {
print("<A HREF=\"".$_SERVER['PHP_SELF']."\">Go to Main Page</A>\n");
}
}
if (!isset($forum)) {
$forum = new SForum;
}
?>