...

View Full Version : Reply to topic, Doesnt insert data into SQL Table `replys`



Scowen
03-12-2010, 10:37 PM
Users are able to post topics and the topics are listed but thy cant reply, can someone find the error in the file?



<style type="text/css">

.content { width: 100%;
padding: 0px; }

.contenthead { background-color: #333;
border: 1px solid #444;
padding: 5px;
color: #111;
font-weight: bold;
font-size: 12px; }
.contentcontent { background-color: #333;
border: 1px solid #444;
padding: 3px;
color: #111;
font-size: 11px; }



.head, .headbox , .dynabox , a.leftmenu , a.topmenu {
margin-left: 8px;
font-weight : bold;
text-decoration : none;
font-size : 80%;
font-family : Verdana, "Lucida Sans", Arial, Geneva, Helvetica, Helv, "Myriad Web", Syntax, sans-serif;
}

a{
color: <?= $color[9] ?>;
}
a:hover{
color: #FFFFFF;
text-decoration: underline;
}
.style1 {color: #BDBDBD}
.style2 {
font-size: 36px;
font-weight: bold;
color: #FFFFFF;
}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
body,td,th {
font-family: Verdana, Lucida Sans, Arial, Geneva, Helvetica, Helv, Myriad Web, Syntax, sans-serif;
color: #FFFFFF;
}
</style>
<?
session_start();
include "dbcon.php";
include "classes.php";
$user_class = new User($_SESSION['id']);
$forum=$_GET['forum'];
$username=$user_class->username;
$viewtopic = $_GET['viewtopic'];
$forum_look=$_GET['forum_look'];


if (!$viewtopic){
$viewtopic = "1";
}
$fetch=mysql_fetch_object(mysql_query("SELECT * FROM grpgusers WHERE username='$username'"));
if ($forum == "Crew" && $user_class->gang != "0"){
$crew="1";

}
$owner=mysql_num_rows(mysql_query("SELECT * FROM gangs WHERE leader='$username' OR coleader='$username'"));


$userlevel=$user_class->admin;





$ggee = mysql_query("SELECT locked, sticky, lastreply FROM topics WHERE id='$viewtopic' AND forum='$forum'");
while($dsdsd = mysql_fetch_row($ggee)){
$lockedornot = $dsdsd[0];
$stikornot = $dsdsd[1];
$lastreplyit = $dsdsd[2];
}

if ($lockedornot == '1'){
echo "This topic is locked.";
}elseif ($user_class->admin != '0' || $lockedornot != '1'){

if ($crew == "1"){
$gg = mysql_query("SELECT * FROM topics WHERE id='$viewtopic' AND forum='$forum' AND crew='$user_class->gang'");
}else{
$gg = mysql_query("SELECT * FROM topics WHERE id='$viewtopic' AND forum='$forum'");
}
while($success = mysql_fetch_row($gg)){
$username1 = $success[1];
$topictext = $success[3];
$made = $success[8];

}




?>
<table width='100%' border='1' cellspacing='0' cellpadding='2' class='content' bordercolor='black'><tr><td class='contentcontent'><center class=TableHeading>Topic Made By : <? echo "<a href='profile.php?viewuser=$username1' target=middle>$username1</a>"; ?> On :<?php echo "$made"; ?></center></td></tr>

<tr><td>

<? echo $topictext;
if ($topictext == ""){ $topictext = "Main Forum";}?>


</td></tr></table><br>
<p>


<?php

$forum_count = 15;

function index_navigation($index, $count, $num) {
$forum = $_GET['forum'];
$viewtopic = $_GET['viewtopic'];
if ($index != 0) {
print "<a href=\"right.php?forum=$forum&viewtopic=$viewtopic&forum_look=" . ($index - $count) . "\">Previous</a> ";
}
if ($num == $count) {
print " <a href=\"right.php?forum=$forum&viewtopic=$viewtopic&forum_look=" . ($index + $count) . "\">Next</a>";
}


}
if (! isset($forum_look) ) {
$forum_look = 0;
}
if ($crew == "1"){
$query="SELECT * FROM replys WHERE idto = '$viewtopic' AND forum='$forum' AND crew='$user_class->gang' ORDER by `id` DESC LIMIT $forum_look, $forum_count";
}else{
$query="SELECT * FROM replys WHERE idto = '$viewtopic' AND forum='$forum' ORDER by `id` DESC LIMIT $forum_look, $forum_count";
}


$query=mysql_query("$query");
$num=mysql_num_rows($query);
while($right=mysql_fetch_object($query)){




if ($user_class->admin > "0"){


echo "<table width=100% cellspacing=0 cellpadding=2 border=1 class='content' bordercolor=black><tr><td class='contentcontent'><a href='profile.php?viewuser=$right->username' target=middle>$right->username</a> <b>On:</b> $right->made</td></tr>

<tr> <td>";

echo $right->text;


echo "</td></tr></table><br>
<p>";
}elseif ($user_class->admin == 0){
echo "<table width=100% cellspacing=0 cellpadding=2 border=1 class=thinline bordercolor=black><tr><td background=includes/grad.jpg><a href='profile.php?viewuser=$right->username'>$right->username</a> <b>On:</b> $right->made</td></tr>
<tr><td bgcolor=black height=1></td></tr>
<tr><td>";

echo ($right->text);


echo "</td></tr></table><br>
<p>";
}



}

if($_GET[clean]) {
$clean=$_GET[clean];
if($user_class->admin == '0'){
echo "Error.";
exit;
}else
mysql_query("DELETE FROM replys WHERE id='$clean' AND forum='$forum'") or die ("Cannot delete reply");
echo "Reply Deleted!";
echo "<SCRIPT LANGUAGE='JavaScript'>
window.location='right.php?forum=$forum&viewtopic=$g';
</script>";

}





?>
<?php
index_navigation($forum_look, $forum_count, $num);
?>





<br>

<br>


<?

if (!$viewtopic){
$viewtopic = "1";
}

if(strip_tags($_POST['Submit']) && strip_tags($_POST['reply_text']) && $forum && $viewtopic){

$reply_text = addslashes(strip_tags($_POST['reply_text']));

$topic_info=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$viewtopic' AND forum='$forum'"));


if ($topic_info->sticky == "1"){
$lastreplytime = $topic_info->lastreply;
}elseif ($stikornot == "0"){
$lastreplytime = time();
}
if ($topic_info->locked == "1"){
echo "This topic is locked.";
exit();
}


$date = date(F." ".d.", ".Y." ".g.":".i.":".sa,time());





if ($crew == "1" && $user_class->gang != "0"){
mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`,`crew`) VALUES ('', '$username', '$reply_text', '$forum', '$viewtopic','$date','$user_class->gang');") or die (mysql_error());
}else{
mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`) VALUES ('', '$username', '$reply_text', '', '$viewtopic','$date');") or die (mysql_error());

}
mysql_query("UPDATE `grpgusers` SET `posts`=`posts`+1 WHERE username='$username'");

mysql_query("UPDATE topics SET lastreply='$lastreplytime' WHERE id='$viewtopic'");
echo "

<SCRIPT LANGUAGE='JavaScript'>
window.location='right.php?forum=$forum&viewtopic=$viewtopic';
</script>";

}
?>


<script language=JavaScript>
function so(dis)
{
for (i=0;i<dis.elements.length;i++){
if (dis.elements[i].type=='submit')
dis.elements[i].style.visibility='hidden';
}
if(fs==false){
fs=true;
return true;
}else
return false;
}
function goaway()
{
for(i=0;i<document.forms.length;i++)
document.forms[i].onsubmit = function() {return so(this);};
}
</script><body onload=goaway();>


<form action='' method='post'>
<input name="forumto" type="hidden" value="<?php echo "$forum"; ?>">
<input name="this" type="hidden" id="this" value="<?php echo "$viewtopic"; ?>">

<table class='content' border='1' cellspacing='0' cellpadding='2' width='100%' bordercolor="black">
<tr>
<td class='contentcontent'><center><font color=#FFFFFF>Reply:</font></center></td>
</tr>
<tr>
<td ><center> <div align="center">
<textarea name="reply_text" cols="" rows="5" id="reply_text" style="width: 90%;"></textarea>
<br>
</div></td>
</tr>
<tr>
<td width=33% class='contentcontent'><center><input type=submit value=Submit name=Submit></td>
</tr>
</table>
</form>
<? } ?>

masterofollies
03-12-2010, 10:43 PM
Can you post just the reply area of the script?

Also what kind of an error does it give you?

Scowen
03-12-2010, 10:52 PM
That is, the reply to the topic is also in the same part as the view topic.

Also it doesn't give an error, it doesn't send the data to the database.

Nightfire
03-13-2010, 12:46 AM
Lots of problems there.

No html tag, no head, body tag near end of page, starting a session not at the top of the page, no closing head, no closing body and no closing html

That shouldn't even work at all, as the session should never be started, you should've got a warning about headers already been sent



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum