Php ile Forum Yazmak | Kendi Forumunuzu Kodlayın

12.07.2009 15:20 — Programlama, Webmaster,

Bu yazıda php kodlama diliyle bir forum nasıl kodlanır onu anlatmaya çalışacağım. Adım adım uygularsanız iÅŸlem sonunda basit bir forum scripti elde etmiÅŸ olacaksınız. Bu forumu geliÅŸtirmek size kalmış. Bu bir baÅŸlangıçtır ve mantığını kavrama amaçlı verilmiÅŸtir. GeliÅŸmiÅŸ özellikler eklemek sizin kodlama bilginize kalmıştır. Hadi baÅŸlayalım canlarım... ilk Önce Tablolarimizi Olusturuyoruz; Katagori Tablolari

Kod:
create table categories(
  id int(4) not null auto_increment,
  title varchar(255) not null,
  description varchar(255) not null,
  primary key(id)
);

Forum Tablolari

Kod:
create table forums(
  id int(4) not null auto_increment,
  cid int(4) not null,
  title varchar(255) not null,
  description longtext not null,
  last_post_title varchar(255) not null,
  last_post_username varchar(32) not null,
  topics int(9) not null,
  replies int(9) not null,
  primary key(id)
);

Gönderilen Basliklar Tablolari

Kod:
create table topics(
  id int(9) not null auto_increment,
  timestamp int(20) not null,
  fid int(4) not null,
  title varchar(255) not null,
  post longtext not null,
  username varchar(32) not null,
  last_post_username varchar(32) not null,
  replies int(9) not null,
  views int(9) not null,
  primary key(id)
);

Gönderilen Mesajlar Tablolari

Kod:
create table replies(
  id int(9) not null auto_increment,
  tid int(9) not null,
  post longtext not null,
  username varchar(32) not null,
  primary key(id)
);

Tablolarimizi Olusturduk Simdi Baglanti dosyalari,index,katagori ekleme,forum ekleme,forum görüntüle,mesaj ekleme,mesaj görüntüle gibi dosyalari olusturacagiz database.php [ Baglanti ]

Kod:
<?
mysql_connect("localhost", "db ismi", "db sifresi");
// alt kisimada Olusturdugumuz databese ismini yaziyoruz.
mysql_select_db("database");
?>

index.php [ Ana Sayfa ]

Kod:
<?
// Baglantiyi include ediyoruz.
include ("database.php"); 

// Bu kisimda Baglantigi kurdukdan Sonra tablomuza Baglanip kategori tablomuza baglaniyoruz
$result = mysql_query("select * from categories order by id asc") or die(mysql_error()); 

   while($r = mysql_fetch_array($result))
   {
      // redefine our category row variables.
      $category_id = $r['id'];
      $category_title = $r['title'];
      $category_description = $r['description'];
?>
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td colspan="4" style="background-color:#eee;"><? echo $category_title; ?><br />
    <? echo $category_description; ?></td>
  </tr>
<? 

     $result2 = mysql_query("select * from forums where cid = '$category_id'"); 

     while($r2 = mysql_fetch_array($result2))
     { 

        $forum_id = $r2['id'];
        $forum_title = $r2['title'];
        $forum_description = $r2['description'];
        $forum_last_post_title = $r2['last_post_title'];
        $forum_last_post_username = $r2['last_post_username'];
        $forum_topics = $r2['topics'];
        $forum_replies = $r2['replies'];
?>
  <tr>
    <td style="width:50%;background-color:#fafafa;">
    <a href="viewforum.php?f=<? echo $forum_id; ?>"><? echo $forum_title; ?></a><br />
    <? echo $forum_description; ?>
    </td>
    <td style="width:30%;background-color:#fafafa;">
    <? echo $forum_last_post_title; ?><br />
    <? echo $forum_last_post_username; ?>
    </td>
    <td style="width:10%;background-color:#fafafa;"><? echo $forum_topics; ?></td>
    <td style="width:10%;background-color:#fafafa;"><? echo $forum_replies; ?></td>
  </tr>
<?
      }
?>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
<?
}
?>

add_category.php [ Kategori Ekle ]

Kod:
<?
// Baglanti include Ediyoruz.
include ("database.php"); 

if(isset($_POST['addcategory']) && !empty($_POST['title']))
{ 

   $title = $_POST['title'];
   $description = $_POST['description']; 

   mysql_query("insert into categories values('null', '$title', '$description')");
   echo "<b> The Category Was added Successfully.</b><br /> \n";
}
?>
<h1>Kategori Ekle</h1>
<form action="add_category.php" method="post">
Kategori Basligi:<br />
<input type="text" name="title" /><br />
Aciklamasi:<br />
<input type="text" name="description" /><br />
<input type="submit" value="Add Category" name="addcategory" />
</form>

add_forum.php [ Forum Ekle ]

Kod:
<?
// Her Zamanki gibi baglanti include ediyoruz.
include ("database.php"); 

if(isset($_POST['addforum']) && !empty($_POST['title']))
{ 

   $title = $_POST['title'];
   $description = $_POST['description'];
   $cid = $_POST['cid']; 

   mysql_query("insert into forums (id, cid, title, description)
      values('null', '$cid', '$title', '$description')");
   echo "<b> The forum was added successfully.</b><br /> \n";
}
?>
<h1>Forum Ekle</h1>
<? 

$result = mysql_query("select id, title from categories order by title asc"); 

if(mysql_num_rows($result) < 1)
{
   echo "You need to add categories first. \n";
}
// else, display the form.
else
{
?>
<form action="add_forum.php" method="post">
Add to which category?<br />
<select name="cid">
<? 

   while($r = mysql_fetch_array($result))
   {
      echo "<option value=\"". $r['id'] ."\">". $r['title'] ."</option> \n";
   }
?>
</select><br />
FORUM Baslik:<br />
<input type="text" name="title" /><br />
FORUM Aciklama:<br />
<input type="text" name="description" /><br />
<input type="submit" value="Add Category" name="addforum" />
</form>
<?
}
?>

viewforum.php [ Forum Görüntüle ]

Kod:
<?
// Baglanti include.
include ("database.php"); 

$f = $_GET['f']; 

$result = mysql_query("select title from forums where id = '$f'"); 

$result2 = mysql_query("select * from topics where fid = '$f' order by timestamp desc"); 

$r = mysql_fetch_array($result); 

$forum_title = $r['title'];
?> 

<b>Görüntüleme: <? echo $forum_title; ?></b><br /><br /> 

<a href="addthread.php?f=<? echo $f; ?>">Cevap Yaz</a><br /> 

<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td style="background-color:#eee;">Baslatan</td>
    <td style="background-color:#eee;">Son Mesaj</td>
    <td style="background-color:#eee;">Cevaplar</td>
    <td style="background-color:#eee;">Görüntüleme</td>
  </tr>
<? 

while($r2 = mysql_fetch_array($result2))
{ 

   $thread_id = $r2['id'];
   $thread_title = $r2['title'];
   $thread_username = $r2['username'];
   $thread_last_post_username = $r2['last_post_username'];
   $thread_replies = $r2['replies'];
   $thread_views = $r2['views'];
?>
  <tr>
    <td style="width:50%;background-color:#fafafa;">
    <a href="viewthread.php?t=<? echo $thread_id; ?>"><? echo $thread_title; ?></a>
    <br />started by: <b><? echo $thread_username; ?></b>
    </td>
    <td style="width:30%;background-color:#fafafa;"><? echo $thread_last_post_username; ?></td>
    <td style="width:10%;background-color:#fafafa;"><? echo $thread_replies; ?></td>
    <td style="width:10%;background-color:#fafafa;"><? echo $thread_views; ?></td>
  </tr>
<?
}
?>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>

addthread.php [ Mesaj Ekle ]

Kod:
<?
// Baglanti include
include ("database.php"); 

$f = $_GET['f']; 

$result = mysql_query("select title from forums where id = '$f'");
$r = mysql_fetch_array($result);
?>
<? 

if(isset($_POST['preview']))
{
?>
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td colspan="2" style="background-color:#eee;"><? echo $_POST['title']; ?></td>
  </tr>
  <tr>
    <td style="width:25%;background-color:#fafafa;" valign="top">
    <? echo $_POST['username']; ?></td>
    <td style="width:75%;background-color:#fafafa;" valign="top">
    <? 

    echo nl2br(htmlspecialchars($_POST['post']));
    ?>
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
<br />
<?
}
?>
<? 

if(isset($_POST['addthread']) && !empty($_POST['title']) && !empty($_POST['username'])
   && !empty($_POST['post']))
{ 

   $f = $_POST['f'];
   $title = addslashes(htmlspecialchars($_POST['title']));
   $username = addslashes(htmlspecialchars($_POST['username']));
   $post = addslashes(htmlspecialchars($_POST['post'])); 

   $timestamp = time(); 

   mysql_query("insert into topics (id, fid, title, username, post, last_post_username, timestamp)
      values('null', '$f', '$title', '$username', '$post', '$username', '$timestamp')"); 

   $add_count_result = mysql_query("select topics from forums where id = '$f'");
   $add_count_row = mysql_fetch_array($add_count_result);
   $add_count = $add_count_row['topics']+1; 

   .
   mysql_query("update forums set topics = '$add_count' where id = '$f'"); 

   $thread_id_result = mysql_query("select id from topics order by id desc limit 1");
   $thread_id_row = mysql_fetch_array($thread_id_result);
   $t = $thread_id_row['id'];
?>
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td style="background-color:#eee;">Mesajiniz Eklendi</td>
  </tr>
  <tr>
    <td style="width:75%;background-color:#fafafa;" valign="top">
    Your Thread was added successfully.<br />
    <a href="viewthread.php?t=<? echo $t; ?>">Görüntülemek icin tiklayin</a>
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
<?
}
else{ 

<form action="addthread.php" method="post">
<input type="hidden" value="<? if(isset($_POST['f'])){ echo $_POST['f']; } else{ echo $f; } ?>"
name="f" />
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td colspan="2"style="background-color:#eee;">Adding Forum to: <? echo $r['title']; ?></td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;">isim:</td>
    <td style="width:85%;background-color:#fafafa;">
    <input type="text" name="username"
    value="<? if(isset($_POST['username'])){ echo $_POST['username']; } ?>" />
    </td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;">Cevap Basligi:</td>
    <td style="width:85%;background-color:#fafafa;">
    <input type="text" name="title"
     value="<? if(isset($_POST['title'])){ echo $_POST['title']; } ?>" />
    </td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;" valign="top">Mesajiniz:</td>
    <td style="width:85%;background-color:#fafafa;">
<textarea name="post" cols="" rows="" style="width:80%;height:200px;">
<? if(isset($_POST['post'])){ echo $_POST['post']; } ?>
</textarea>
    </td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;" valign="top">&nbsp;</td>
    <td style="width:85%;background-color:#fafafa;">
    <input type="submit" name="preview" value="Önizleme" />
    <input type="submit" name="addthread" value="Gönder" />
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
</form>
<?
}
?>

viewthread.php [ Mesaj Görüntüleme ]

Kod:
<?
// baglanti.
include ("database.php"); 

$t = $_GET['t']; 

$result = mysql_query("select * from topics where id = '$t'"); 

$result2 = mysql_query("select * from replies where tid = '$t'"); 

$r = mysql_fetch_array($result); 

$topic_title = $r['title']; 

$add_count = $r['views']+1;
mysql_query("update topics set views = '$add_count' where id = '$t'");
?> 

<a href="addreply.php?t=<? echo $t; ?>">Cevap Ekle</a><br />
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td style="background-color:#eee;" colspan="2"><? echo $topic_title; ?></td>
  </tr>
  <tr>
    <td style="width:20%;background-color:#fafafa;" valign="top">
    <? 

    echo stripslashes($r['username']); ?></td>
    <td style="width:80%;background-color:#fafafa;">
    <?  

    echo nl2br(stripslashes($r['post'])); ?></td>
  </tr>
</table> 

<? 

while($r2 = mysql_fetch_array($result2))
{
?>
<br />
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td style="background-color:#eee;" colspan="2">re: <? echo $topic_title; ?></td>
  </tr>
  <tr>
    <td style="width:20%;background-color:#fafafa;" valign="top">
    <? echo stripslashes($r2['username']); ?></td>
    <td style="width:80%;background-color:#fafafa;">
    <? echo nl2br(stripslashes($r2['post'])); ?></td>
  </tr>
</table>
<?
}
?>

addreply.php [ Mesaj Ekle ]

Kod:
<?
// Baglanti include.
include ("database.php"); 

$t = $_GET['t']; 

$result = mysql_query("select title, fid from topics where id = '$t'");
$r = mysql_fetch_array($result);
$f = $r['fid'];
?>
<? 

if(isset($_POST['preview']))
{
?>
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td colspan="2" style="background-color:#eee;">re: <? echo $_POST['title']; ?></td>
  </tr>
  <tr>
    <td style="width:25%;background-color:#fafafa;" valign="top">
    <? echo $_POST['username']; ?></td>
    <td style="width:75%;background-color:#fafafa;" valign="top">
    <? 

    echo nl2br(htmlspecialchars($_POST['post']));
    ?>
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
<br />
<?
}
?>
<? 

if(isset($_POST['addreply']) && !empty($_POST['username'])
   && !empty($_POST['post']))
{ 

   $t = $_POST['t'];
   $f = $_POST['f'];
   $username = addslashes(htmlspecialchars($_POST['username']));
   $post = addslashes(htmlspecialchars($_POST['post'])); 

   $timestamp = time(); 

   mysql_query("insert into replies (id, tid, username, post)
      values('null', '$t', '$username', '$post')"); 

   $add_count_forum_result = mysql_query("select replies from forums where id = '$f'");
   $add_count_topic_result = mysql_query("select replies from topics where id = '$t'");
   $add_count_forum_row = mysql_fetch_array($add_count_forum_result);
   $add_count_topic_row = mysql_fetch_array($add_count_topic_result);
   $add_count_forum = $add_count_forum_row['replies']+1;
   $add_count_topic = $add_count_topic_row['replies']+1; 

   mysql_query("update forums set replies = '$add_count_forum' where id = '$f'");
   mysql_query("update topics set replies = '$add_count_topic', timestamp = '$timestamp'
                where id = '$t'");
?>
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td style="background-color:#eee;">Mesaj Eklendi</td>
  </tr>
  <tr>
    <td style="width:75%;background-color:#fafafa;" valign="top">
    Your Reply was added successfully.<br />
    <a href="viewthread.php?t=<? echo $t; ?>">Görüntülemek icin tiklayiniz.</a>
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
<?
}
else{ 

<form action="addreply.php" method="post">
<input type="hidden"
value="<? if(isset($_POST['t'])){ echo $_POST['t']; } else{ echo $t; } ?>" name="t" />
<input type="hidden"
value="<? if(isset($_POST['f'])){ echo $_POST['f']; } else{ echo $f; } ?>" name="f" />
<table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
  <tr>
    <td colspan="2"style="background-color:#eee;">Mesaj Buraya Ekleniyor: <? echo $r['title']; ?></td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;">isim:</td>
    <td style="width:85%;background-color:#fafafa;">
    <input type="text" name="username"
    value="<? if(isset($_POST['username'])){ echo $_POST['username']; } ?>" />
    </td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;" valign="top">Mesajiniz:</td>
    <td style="width:85%;background-color:#fafafa;">
<textarea name="post" cols="" rows="" style="width:80%;height:200px;">
<? if(isset($_POST['post'])){ echo $_POST['post']; } ?>
</textarea>
    </td>
  </tr>
  <tr>
    <td style="width:15%;background-color:#fafafa;" valign="top">&nbsp;</td>
    <td style="width:85%;background-color:#fafafa;">
    <input type="submit" name="preview" value="Önizleme" />
    <input type="submit" name="addreply" value="Postala" />
    </td>
  </tr>
  <tr>
    <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
  </tr>
</table>
</form>
<?
}
?>

İşlemler bu kadar.

    Yorumlar...
    (Toplam 20 yorum var.)


    Sayfa: <<<1 2

    Bu yorumu gerçekten şikayet etmek istiyor musunuz ???


    Bir sebep belirtmek isterseniz alttaki kutucuÄŸa yazabilirsiniz...




    Pencereyi Kapat...
  1. 14.02.2012 20:47


    Admin
    Yorum: 296
    Forum Mesaj: 224




    @ QFUSION:

    GiriÅŸ iÅŸlemindeki dbuser ve dbpass ikilisi sql kullanıcı adı ve ÅŸifresidir ve veritabanına giriÅŸ izni içindir. Üyelik yada admin giriÅŸ iÅŸlemiyle alakası yok.

     

    SQL olarak admin giriÅŸini sorgulatma kısmına gelince. Sizin için bir örnek oluÅŸturdum.

    Mysql'de bir tablo oluşturursunuz, burada admin login adı şifresi ve diğer isteğe bağlı bilgiler yer alır;

    veritabanı adı: admin_tablo

    CREATE TABLE IF NOT EXISTS `admin_tablo` (
      `kullanici_adi` varchar(100) NOT NULL,
      `sifre` int(100) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    --
    -- Tablo döküm verisi `admin_tablo`
    --
    
    INSERT INTO `admin_tablo` (`kullanici_adi`, `sifre`) VALUES
    ('admin', 12345);

     

    Admin giriş sayfası;

     

    <form method="POST" action="giris_kontrol.php">
    	<input type="text" name="k_adi" size="20">
    	<input type="password" name="sifre" size="20">
    	<input type="submit" value="GiriÅŸ" name="B1">
    </form>

     

    admin giriş bilgileri kontrol sayfası; giris_kontrol.php

    <?php
        //Mysql bağlantısını yapıyoruz.
        mysql_connect("localhost", "mysql_kullanici_adi", "mysql_kullanici_sifresi");
        mysql_select_db("veritabani_adi");
    
    
        //form ile post edilen veriler
        $k_adi = $_POST['kullanici_adi'];
        $sifre = $_POST['sifre'];
    
        //Mysql'den form verilerini kontrol ediyoruz
        $admin_kontrol_sql = mysql_query("SELECT kullanici_adi, sifre FROM admin_tablo WHERE kullanici_adi='$k_adi' AND sifre='$sifre' LIMIT 1");
        if (mysql_fetch_assoc($admin_kontrol_sql) == 1 ) {
            echo 'Giriş başarılı';
        }else{
            echo 'Hatalı giriş !...';
        }
    ?>

  2. 15.02.2012 08:10
    QFUSION


    Misafir




      mysql de böyle bir hata verdi Otomatik olarak sorgunun sonuna ters iÅŸaret ekle

    CREATE TABLE IF NOT EXISTS `admin_tablo` (

    `kullanici_adi` varchar( 100 ) NOT NULL ,
    `sifre` int( 100 ) NOT NULL

    ) ENGINE = MYISAM DEFAULT CHARSET = latin1;# MySQL boÅŸ bir sonuç kümesi döndürdü (örn. sıfır satır).
    --
    -- Tablo d�k�m verisi `admin_tablo` --
    INSERT INTO `admin_tablo` (` kullanici_adi `, `sif re `) VALUES ('admin', 12345);# ` 1 satır etkilendi.


  3. 15.02.2012 10:21


    Admin
    Yorum: 296
    Forum Mesaj: 224




    Mysql sürümünüzle ilgili bir sorun oluÅŸmuÅŸ galiba. Farketmez, yapacağınız iÅŸlem basit.

    admin_tablo isminde 2 sütunlu bir tablo oluÅŸturun. Sütunlardan birinin adı; kullanici_adi diÄŸeride sifre olsun. Tabloyu ekledikten sonra içine girin ve ekle kısmından Ekle sekmesine tıklayın. kullanici_adi: admin sifre'de 12345 olsun. Çalışması gerekiyor...


  4. 16.02.2012 07:34
    ahmetusta0061


    Misafir




    Bişeyi merak ettim,php sayfalarının ismi ingilizce olmak zorundamı..? Mesela addforum değilde forumekle.php olmazmı.Kodlama diliyle ilgili olarakmı ingilizce yapıyoruz sayfaları..?


  5. 16.02.2012 07:46


    Admin
    Yorum: 296
    Forum Mesaj: 224




    @ ahmetusta0061:

    Bunun hiç bir önemi yok. İstediÄŸiniz gibi isimlendirebilirsiniz.


  6. 12.03.2012 21:55
    QFUSION


    Misafir




    CSS ile bir şablon oluşturacagım tablonun enini nasıl ayarlayabilirim


  7. 12.03.2012 22:05


    Admin
    Yorum: 296
    Forum Mesaj: 224




    @ QFUSION:


    Bir class verip css ile class'a Width değeri vermeniz yeterli olacaktır.

    Örnek;

    <div class="tablo">Bu bir div örneÄŸidir.</div>

    CSS;

    .tablo {
    width:150px;
    }

  8. 10.04.2012 10:50


    Kayıtlı Üye
    Yorum: 1
    Forum Mesaj: 0




    addthread.php

     

    <?

    // Baglanti include
    include ("database.php"); 
    
    $f = $_GET['f']; 
    
    $result = mysql_query("select title from forums where id = '$f'");
    $r = mysql_fetch_array($result);
    ?>
    <? 
    
    if(isset($_POST['preview']))
    {
    ?>
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td colspan="2" style="background-color:#eee;"><? echo $_POST['title']; ?></td>
      </tr>
      <tr>
        <td style="width:25%;background-color:#fafafa;" valign="top">
        <? echo $_POST['username']; ?></td>
        <td style="width:75%;background-color:#fafafa;" valign="top">
        <? 
    
        echo nl2br(htmlspecialchars($_POST['post']));
        ?>
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    <br />
    <?
    }
    ?>
    <? 
    
    if(isset($_POST['addthread']) && !empty($_POST['title']) && !empty($_POST['username'])
       && !empty($_POST['post']))
    { 
    
       $f = $_POST['f'];
       $title = addslashes(htmlspecialchars($_POST['title']));
       $username = addslashes(htmlspecialchars($_POST['username']));
       $post = addslashes(htmlspecialchars($_POST['post'])); 
    
       $timestamp = time(); 
    
       mysql_query("insert into topics (id, fid, title, username, post, last_post_username, timestamp)
          values('null', '$f', '$title', '$username', '$post', '$username', '$timestamp')"); 
    
       $add_count_result = mysql_query("select topics from forums where id = '$f'");
       $add_count_row = mysql_fetch_array($add_count_result);
       $add_count = $add_count_row['topics']+1; 
    
       .
       mysql_query("update forums set topics = '$add_count' where id = '$f'"); 
    
       $thread_id_result = mysql_query("select id from topics order by id desc limit 1");
       $thread_id_row = mysql_fetch_array($thread_id_result);
       $t = $thread_id_row['id'];
    ?>
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td style="background-color:#eee;">Mesajiniz Eklendi</td>
      </tr>
      <tr>
        <td style="width:75%;background-color:#fafafa;" valign="top">
        Your Thread was added successfully.<br />
        <a href="viewthread.php?t=<? echo $t; ?>">Görüntülemek icin tiklayin</a>
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    <?
    }
    else{ 
    
    <form action="addthread.php" method="post">
    <input type="hidden" value="<? if(isset($_POST['f'])){ echo $_POST['f']; } else{ echo $f; } ?>"
    name="f" />
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td colspan="2"style="background-color:#eee;">Adding Forum to: <? echo $r['title']; ?></td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;">isim:</td>
        <td style="width:85%;background-color:#fafafa;">
        <input type="text" name="username"
        value="<? if(isset($_POST['username'])){ echo $_POST['username']; } ?>" />
        </td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;">Cevap Basligi:</td>
        <td style="width:85%;background-color:#fafafa;">
        <input type="text" name="title"
         value="<? if(isset($_POST['title'])){ echo $_POST['title']; } ?>" />
        </td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;" valign="top">Mesajiniz:</td>
        <td style="width:85%;background-color:#fafafa;">
    <textarea name="post" cols="" rows="" style="width:80%;height:200px;">
    <? if(isset($_POST['post'])){ echo $_POST['post']; } ?>
    </textarea>
        </td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;" valign="top">&nbsp;</td>
        <td style="width:85%;background-color:#fafafa;">
        <input type="submit" name="preview" value="Önizleme" />
        <input type="submit" name="addthread" value="Gönder" />
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    </form>
    <?
    }
    ?>

     

    addreply.php

     

    <?

    // Baglanti include.
    include ("database.php"); 
    
    $t = $_GET['t']; 
    
    $result = mysql_query("select title, fid from topics where id = '$t'");
    $r = mysql_fetch_array($result);
    $f = $r['fid'];
    ?>
    <? 
    
    if(isset($_POST['preview']))
    {
    ?>
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td colspan="2" style="background-color:#eee;">re: <? echo $_POST['title']; ?></td>
      </tr>
      <tr>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        <td style="width:25%;background-color:#fafafa;" valign="top">
        <? echo $_POST['username']; ?></td>
        <td style="width:75%;background-color:#fafafa;" valign="top">
        <? 
    
        echo nl2br(htmlspecialchars($_POST['post']));
        ?>
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    <br />
    <?
    }
    ?>
    <? 
    
    if(isset($_POST['addreply']) && !empty($_POST['username'])
       && !empty($_POST['post']))
    { 
    
       $t = $_POST['t'];
       $f = $_POST['f'];
       $username = addslashes(htmlspecialchars($_POST['username']));
       $post = addslashes(htmlspecialchars($_POST['post'])); 
    
       $timestamp = time(); 
    
       mysql_query("insert into replies (id, tid, username, post)
          values('null', '$t', '$username', '$post')"); 
    
       $add_count_forum_result = mysql_query("select replies from forums where id = '$f'");
       $add_count_topic_result = mysql_query("select replies from topics where id = '$t'");
       $add_count_forum_row = mysql_fetch_array($add_count_forum_result);
       $add_count_topic_row = mysql_fetch_array($add_count_topic_result);
       $add_count_forum = $add_count_forum_row['replies']+1;
       $add_count_topic = $add_count_topic_row['replies']+1; 
    
       mysql_query("update forums set replies = '$add_count_forum' where id = '$f'");
       mysql_query("update topics set replies = '$add_count_topic', timestamp = '$timestamp'
                    where id = '$t'");
    ?>
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td style="background-color:#eee;">Mesaj Eklendi</td>
      </tr>
      <tr>
        <td style="width:75%;background-color:#fafafa;" valign="top">
        Your Reply was added successfully.<br />
        <a href="viewthread.php?t=<? echo $t; ?>">Görüntülemek icin tiklayiniz.</a>
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    <?
    }
    else{ 
    
    <form action="addreply.php" method="post">
    <input type="hidden"
    value="<? if(isset($_POST['t'])){ echo $_POST['t']; } else{ echo $t; } ?>" name="t" />
    <input type="hidden"
    value="<? if(isset($_POST['f'])){ echo $_POST['f']; } else{ echo $f; } ?>" name="f" />
    <table cellpadding="5" cellspacing="1" border="0" style="width:90%;border:1px solid #000;">
      <tr>
        <td colspan="2"style="background-color:#eee;">Mesaj Buraya Ekleniyor: <? echo $r['title']; ?></td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;">isim:</td>
        <td style="width:85%;background-color:#fafafa;">
        <input type="text" name="username"
        value="<? if(isset($_POST['username'])){ echo $_POST['username']; } ?>" />
        </td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;" valign="top">Mesajiniz:</td>
        <td style="width:85%;background-color:#fafafa;">
    <textarea name="post" cols="" rows="" style="width:80%;height:200px;">
    <? if(isset($_POST['post'])){ echo $_POST['post']; } ?>
    </textarea>
        </td>
      </tr>
      <tr>
        <td style="width:15%;background-color:#fafafa;" valign="top">&nbsp;</td>
        <td style="width:85%;background-color:#fafafa;">
        <input type="submit" name="preview" value="Önizleme" />
        <input type="submit" name="addreply" value="Postala" />
        </td>
      </tr>
      <tr>
        <td style="background-color:#eee;font-size:0;height:15px;" colspan="4">&nbsp;</td>
      </tr>
    </table>
    </form>
    <?
    }
    ?>

    Yukarıdaki sayfalarda hata alıyorum lütfen bir bakar mısınız.Acilll yardım edin!!!


  9. 11.04.2012 08:07


    Admin
    Yorum: 296
    Forum Mesaj: 224




    @ Clamatios:


    Aldığınız hatayı yazar mısınız?


  10. 14.05.2012 20:42
    quaint


    Misafir




    iki dosyadada

    else{

    bölümü

    else{

    ?>

    şeklinde olmalı.

    ve addthread.php de  fazladan bir nokta iÅŸareti var onu silin.


Sayfa:<<<1 2


Yorum Yazın


Yorumları Gizle | İçeriği Gizle