This forum is in archive mode. You will not be able to post new content.

Author Topic: Need help with forum I am making  (Read 2611 times)

0 Members and 2 Guests are viewing this topic.

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Need help with forum I am making
« on: November 18, 2012, 03:49:26 AM »
I'm making a forum for a game I play. I have almost everything done but the forum part. I cant figure out how to post the text the user inputted to the screen.






Heres the code I have so far:
Code: [Select]
<?php
include "config-post.php";
$titlex $_POST['title'];
$areax $_POST['area'];
$bodyx $_POST['body'];
$title strip_tags($titlex);
$area strip_tags($areax);
$body strip_tags($bodyx);
$time date('d/m/y h:i:s');
if(
$area == discussion){
   
$query "INSERT INTO discussion(title, body, time) VALUES ($title$body$time)";
   
$result mysql_query($query);
   if(
$result){
      
header("Location: discussion.php");
   }
}
if(
$area == suggestions){
   
$query2 "INSERT INTO suggestions(title, body, time) VALUES ($title$body$time)";
   
$result2 mysql_query($query2);
   if(
$result2){
      
header("Location: suggestions.php");
   }
}
if(
$area == tips){
   
$query3 "INSERT INTO tips(title, body, time) VALUES ($title$body$time)";
   
$result3 mysql_query($query3);
   if(
$result3){
      
header("Location: tips.php");
   }
}
if(
$area == bugs){
   
$query4 "INSERT INTO bugs(title, body, time) VALUES ($title$body$time)";
   
$result4 mysql_query($query4);
   if(
$result4){
      
header("Location: bugs.php");
   }
}
if(
$area == war_discussion){
   
$query5 "INSERT INTO war discussion(title, body, time) VALUES ($title$body$time)";
   
$result5 mysql_query($query5);
   if(
$result){
      
header("Location: war.php");
   }
}
?>
« Last Edit: November 22, 2012, 02:18:53 AM by jeremy78 »

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: Need help with forum I am making
« Reply #1 on: November 18, 2012, 04:23:58 AM »
dont realy understand what your asking for tbh

but to make the code easier i beleve you can do this insted

Code: (PHP) [Select]
function cleanQuery($string)
{
  if(get_magic_quotes_gpc())
  {
    $string = stripslashes($string);
  }
  if (phpversion() >= '4.3.0')
  {
    $string = mysql_real_escape_string($string);
  }
  else
  {
    $string = mysql_escape_string($string);
  }
  return $string; 
}

$area = cleanQuery($area);

if($area == war_discussion || $area == suggestions || $area == tips){ //fill all the categoris
   $query5 = "INSERT INTO ".$area."(title, body, time) VALUES ($title, $body, $time)";
   $result5 = mysql_query($query5);
   if($result){
      header("Location: ".$area.".php");
   }
}

to read the input use mysql select, on the redirection you can use an id...

please provide more info about whats wrong

edit:
is the error that you have empty $_POST[] ??? check that

and yeah you will ofc need the connection
Code: (PHP) [Select]
$con = mysql_connect("localhost", "root", "pass") or die(mysql_error());
    mysql_select_db("forum") or die(mysql_error());
    mysql_query(insert whatever) or die(mysql_error());
    mysql_close($con);
« Last Edit: November 18, 2012, 04:29:48 AM by relax »

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: Need help with forum I am making
« Reply #2 on: November 18, 2012, 04:39:19 AM »
dont realy understand what your asking for tbh

but to make the code easier i beleve you can do this insted

Code: (PHP) [Select]
function cleanQuery($string)
{
  if(get_magic_quotes_gpc())
  {
    $string = stripslashes($string);
  }
  if (phpversion() >= '4.3.0')
  {
    $string = mysql_real_escape_string($string);
  }
  else
  {
    $string = mysql_escape_string($string);
  }
  return $string; 
}

$area = cleanQuery($area);

if($area == war_discussion || $area == suggestions || $area == tips){ //fill all the categoris
   $query5 = "INSERT INTO ".$area."(title, body, time) VALUES ($title, $body, $time)";
   $result5 = mysql_query($query5);
   if($result){
      header("Location: ".$area.".php");
   }
}

to read the input use mysql select, on the redirection you can use an id...

please provide more info about whats wrong

edit:
is the error that you have empty $_POST[] ??? check that

and yeah you will ofc need the connection
Code: (PHP) [Select]
$con = mysql_connect("localhost", "root", "pass") or die(mysql_error());
    mysql_select_db("forum") or die(mysql_error());
    mysql_query(insert whatever) or die(mysql_error());
    mysql_close($con);

Thanks but I was talking about when you input the text into the form it gets sent to the database and then it gets put on the website so everyone can see it but I cant figure out how to display the text to the screen so everyone can see it.

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: Need help with forum I am making
« Reply #3 on: November 18, 2012, 04:56:29 AM »
Code: (PHP) [Select]
$result = mysql_query("SELECT * FROM posts");
 
 while($row = mysql_fetch_array($result))
   {
   echo $row['name'];
   }

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: Need help with forum I am making
« Reply #4 on: November 18, 2012, 05:09:55 AM »
Code: (PHP) [Select]
$result = mysql_query("SELECT * FROM posts");
 
 while($row = mysql_fetch_array($result))
   {
   echo $row['name'];
   }
Thanks

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: Need help with forum I am making
« Reply #5 on: November 18, 2012, 07:34:50 AM »
+1 for building your own forum and not a script such as SMF, phpBB, vBulletin, or IPB ;)
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Need help with forum I am making
« Reply #6 on: November 18, 2012, 11:54:49 AM »
Yeah gotta make sure to echo  ;)
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Need help with forum I am making
« Reply #7 on: November 19, 2012, 10:40:38 AM »
There are a lot of bugs/wrong things here. Here are a few:

- You should use one table for all forum topics and posts
- You cannot have spaces in your table names
- You should look into OOP
- You should make the arena/category/board stuff dynamically loaded from database
- You should split things into more files
- Always do input validation. SQL escape stuff, RFI, LFI, XSS and CSRF are the big problems.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: Need help with forum I am making
« Reply #8 on: November 19, 2012, 09:29:06 PM »
There are a lot of bugs/wrong things here. Here are a few:

- You should use one table for all forum topics and posts
- You cannot have spaces in your table names
- You should look into OOP
- You should make the arena/category/board stuff dynamically loaded from database
- You should split things into more files
- Always do input validation. SQL escape stuff, RFI, LFI, XSS and CSRF are the big problems.
Yeah I know I need to make it more secure I am working on that now.

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: Need help with forum I am making
« Reply #9 on: November 19, 2012, 10:54:01 PM »
May I ask what game your making the forum for?

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: Need help with forum I am making
« Reply #10 on: November 19, 2012, 11:07:56 PM »
May I ask what game your making the forum for?
Yeah I'm making it for a game called kings empire. Its an app. Right now its only for apple devices but I'm pretty sure they making an android version.

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: Need help with forum I am making
« Reply #11 on: November 19, 2012, 11:57:43 PM »
Yeah I'm making it for a game called kings empire. Its an app. Right now its only for apple devices but I'm pretty sure they making an android version.

OMG your a apple user >.<


Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
Re: Need help with forum I am making
« Reply #12 on: November 20, 2012, 12:20:02 AM »
Why re-invent the wheel when there are more than capable enough and highly customizable forum suites available for free?


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Need help with forum I am making
« Reply #13 on: November 20, 2012, 01:28:34 AM »
Why re-invent the wheel when there are more than capable enough and highly customizable forum suites available for free?
Because it's a great learning experience and there's a greater feeling of achievement.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline jeremy78

  • Serf
  • *
  • Posts: 37
  • Cookies: 9
    • View Profile
Re: Need help with forum I am making
« Reply #14 on: November 20, 2012, 03:24:17 AM »
OMG your a apple user >.<


Yeah but I will say that androids are way better for most things.

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.