kaos Posted June 28, 2010 Share Posted June 28, 2010 Ok so im building an oopen source forum so that i learn along the way. But i have come across a problem with the postbit as i cant get it to show the amount of posts from the users table fetched from the username that posted the post <? include_once("inc/func.php"); include_once("inc/db.php"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM forum_answer WHERE question_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } if(isset($_POST['Submit'])){ // get values that sent from form $a_answer=$_POST['a_answer']; $datetime=gmdate("d/m/y H:i:s"); // create date and time $recentdate=gmdate("d-m-Y g:i A"); //create last post date // Insert answer $sql2="INSERT INTO forum_answer(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$username', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if((!$a_answer)){ $msg = "<td class='warning'>Fill in all fields</td>"; }else{ if($result2){ $msg = "<td class='success'>Successful</td>"; // If added new answer, add value +1 in reply column $sql3="UPDATE forum_question SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); mysql_query("UPDATE forum_user SET post = post+1 WHERE username = '$username'"); mysql_query("UPDATE forum_question SET recent='$username' WHERE id='$id'"); mysql_query("UPDATE forum_question SET recentdate='$recentdate' WHERE id='$id'"); }else{ $msg = "<td class='warning'>Error</td>"; }}} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php // get value of id that sent from address bar $id=$_GET['id']; $sql="SELECT * FROM forum_question WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); $getuser="SELECT * FROM forum_user WHERE username = {$row['category']}"; ?> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="2" class="menutable"> <tr> <? require_once("menu.php"); ?> </tr> </table> <table width="90%" height="63" border="0" cellpadding="0" cellspacing="0" class="maintable" align="center"> <tr> <td class="row"> </td> <td class="row"><? echo $rows['topic']; ?> (<? echo $rows['datetime']; ?>)</td> </tr> <tr> <td width="147"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="row"><? echo"$getuser->avatar"; ?></td> </tr> <tr> <td class="row"><? echo $rows['username']; ?></td> </tr> <tr> <td class="row">Posts <? echo"$getuser->posts"; ?></td> </tr> </table></td> <td width="453" class="row"><? echo "".replace($rows['detail']).""; ?></td> </tr> </table> <BR> <?php $sql2="SELECT * FROM forum_answer WHERE question_id='$id' ORDER BY a_datetime ASC"; $result2=mysql_query($sql2); while($rows=mysql_fetch_array($result2)){ ?> <table width="90%" height="63" border="0" cellpadding="0" cellspacing="0" class="maintable" align="center"> <tr> <td class="row"> </td> <td class="row"><? echo $rows['a_datetime']; ?></td> </tr> <tr> <td width="147"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="row"><? echo"$getuserq->avatar"; ?></td> </tr> <tr> <td class="row"><? echo $rows['a_name']; ?></td> </tr> <tr> <td class="row">Posts <? echo"$getuserq->posts"; ?></td> </tr> </table></td> <td width="453" class="row"><? echo "".replace($rows['a_answer']).""; ?></td> </tr> </table><br> <? } $sql3="SELECT view FROM forum_question WHERE id='$id'"; $result3=mysql_query($sql3); $rows=mysql_fetch_array($result3); $view=$rows['view']; // if have no counter value set counter = 1 if(empty($view)){ $view=1; $sql4="INSERT INTO forum_question(view) VALUES('$view') WHERE id='$id'"; $result4=mysql_query($sql4); } // count more value $addview=$view+1; $sql5="UPDATE forum_question SET view='$addview' WHERE id='$id'"; $result5=mysql_query($sql5); ?> <? if(isloggedin()){ ?> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <? echo "$msg"; ?> </tr> </table> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="maintable"> <tr> <form name="form1" method="post" action=""> <td> <table width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td valign="top"> </td> <td valign="top"> </td> </tr> <tr> <td valign="top"><strong>Reply</strong></td> <td valign="top">:</td> <td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" value="<? echo $id; ?>"></td> <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> </tr> </table> </td> </form> </tr> </table> <? } ?> </body> </html> So basically it should have the username fetched from the post table and the posts under the name from the users table :s could anyone help its the $getuser That i need fixing thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/ Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 And the getuserq dosent work :/ proberly something simple Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078176 Share on other sites More sharing options...
Adam Posted June 28, 2010 Share Posted June 28, 2010 Assuming `username` is varchar data type (i.e. string not numeric), you'd need quotes around the value: $getuser="SELECT * FROM forum_user WHERE username = '{$row['category']}'"; In future I'd just post the relevant code, you'll get probably get more help and a faster response. Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078181 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 Its both the $getuser and $getuserq and it still dosent display posts Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078183 Share on other sites More sharing options...
Adam Posted June 28, 2010 Share Posted June 28, 2010 $getuserq is declared.. where? Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078186 Share on other sites More sharing options...
kaos Posted June 28, 2010 Author Share Posted June 28, 2010 $getuser <?php // get value of id that sent from address bar $id=$_GET['id']; $sql="SELECT * FROM forum_question WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); $getuser="SELECT * FROM forum_user WHERE username = '{$rows['username']}'"; ?> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="2" class="menutable"> <tr> <? require_once("menu.php"); ?> </tr> </table> <table width="90%" height="63" border="0" cellpadding="0" cellspacing="0" class="maintable" align="center"> <tr> <td class="row"> </td> <td class="row"><? echo $rows['topic']; ?> (<? echo $rows['datetime']; ?>)</td> </tr> <tr> <td width="147"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="row"><? echo"$getuser->avatar"; ?></td> </tr> <tr> <td class="row"><? echo $rows['username']; ?></td> </tr> <tr> <td class="row">Posts <? echo"$getuser->post"; ?></td> </tr> </table></td> <td width="453" class="row"><? echo "".replace($rows['detail']).""; ?></td> </tr> </table> $getuserq <?php $sql2="SELECT * FROM forum_answer WHERE question_id='$id' ORDER BY a_datetime ASC"; $result2=mysql_query($sql2); while($rows=mysql_fetch_array($result2)){ $getuserq="SELECT * FROM forum_user WHERE username = '{$rows['username']}'"; ?> <table width="90%" height="63" border="0" cellpadding="0" cellspacing="0" class="maintable" align="center"> <tr> <td class="row"> </td> <td class="row"><? echo $rows['a_datetime']; ?></td> </tr> <tr> <td width="147"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="row"><? echo"$getuserq->avatar"; ?></td> </tr> <tr> <td class="row"><? echo $rows['a_name']; ?></td> </tr> <tr> <td class="row">Posts <? echo"$getuserq->posts"; ?></td> </tr> </table></td> <td width="453" class="row"><? echo "".replace($rows['a_answer']).""; ?></td> </tr> </table><br> Neither show the posts from the author or by the reply post Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078189 Share on other sites More sharing options...
TOA Posted June 28, 2010 Share Posted June 28, 2010 Unless I'm missing something (I just glanced at it), $getuser and $getuserq are just holding sql statements right now, not results Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078208 Share on other sites More sharing options...
Adam Posted June 28, 2010 Share Posted June 28, 2010 I can't see $getuserq anywhere in your original code (possible I'm overlooking it). Reason I was asking is, as DevilsAdvocate pointed out, all you have are the statements. I was assuming $getuserq was going to hold the result resource for $getuser, but obviously it's just another query. Quote Link to comment https://forums.phpfreaks.com/topic/206054-no-error-jsut-dosent-display/#findComment-1078279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.