Jump to content

[SOLVED] Displaying information from a database andinsertion information to a database


loony383

Recommended Posts

Hi im trying to make it so veiw_forum.php?forumid=1 displays all the information from the database that has forumid to the value passed in the varible, but my code isnt working

<html>
<head>
<title>Airboard - Beta</title>
<?php 
include ("menu.php");
include "connect.php"; //mysql db connection here
$forumid = $_GET['forumid'];
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<A href='post.php?forumid=$forumid'>New Topic</a>";
print "<table class='maintable'>";
print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";
$getthreads="SELECT * from forumtutorial_posts where parentid='0' and forumid='$forumid' order by realtime DESC";
$getthreads2=mysql_query($getthreads) or die("Could not get threads");
while($getthreads3=mysql_fetch_array($getthreads2))
{
  $getthreads3[title]=strip_tags($getthreads3[title]);
  $getthreads3[author]=strip_tags($getthreads3[author]);
  print "<tr class='mainrow'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>$getthreads3[showtime]
Last post by $getthreads3[lastposter]</td></tr>";
}
print "</table>";
?>

 

instead its showing all the posts not just ones with forumid to 1.

 

 

Also my 2nd problem is when my post.php?forumid=1 inserts information of the topic to the database it isnt inserting forumid to 1 its leaving it blank, heres my code

<?php
include("include/session.php");
include "header.php";
include ("menu.php");
function checkLogin()

{
  global $database;
  if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid']))
  {
    $this->username = $_SESSION['username'] = $_COOKIE['cookname'];
    $this->userid   = $_SESSION['userid']   = $_COOKIE['cookid'];
  }
}

if ($session->username == 'Guest')
{
echo "You need to login to create a topic";
exit();
}
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<table class='maintables'>";
print "<tr class='headline'><td>Post a message</td></tr>";

print "<tr class='maintables'><td>";

if(isset($_POST['submit']))

{

   $name=$session->username;

   $yourpost=$_POST['yourpost'];
$forumid = $_GET['forumid'];
   $subject=$_POST['subject'];


    if(strlen($yourpost)<1)

   {

      print "You did not type in a post."; //no post entered

   }

   else if(strlen($subject)<1)

   {

      print "You did not enter a subject."; //no subject entered

   }

   else

   {

      $thedate=date("U"); //get unix timestamp

      $displaytime=date("F j, Y, g:i a");

      //we now strip HTML injections

      $subject=strip_tags($subject);

      $name=strip_tags($name);

      $yourpost=strip_tags($yourpost); 

      $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter,forumid) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$forumid')";

      mysql_query($insertpost) or die("Could not insert post"); //insert post

      print "Message posted, go back to <A href='index.php?forumid=$forumid'>Forum</a>.";

   }



}

else

{

   print "<form action='post.php' method='post'>";

   print "Subject:<br>";

   print "<input type='text' name='subject' size='20'><br>";

   print "Your message:<br>";

   print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";

   print "<input type='submit' name='submit' value='submit'></form>";



}

print "</td></tr></table>";
include "footer.php";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.