Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Komentari text-a na web site-u

[es] :: PHP :: Komentari text-a na web site-u

Strane: 1 2

[ Pregleda: 4313 | Odgovora: 20 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

damakii

Član broj: 136925
Poruke: 58
*.dynamic.telemach.ba.



Profil

icon Re: Komentari text-a na web site-u13.02.2012. u 21:28 - pre 148 meseci
Probaj ovako,

Code:
 ovo je koment.php
<?php include("konekcija.php");?>
<table width="920" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="230" valign="top" class="pommeniiza"><table width="230" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30" bgcolor="#002E5F"><table width="230" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="200" height="30" class="kontaktpocetna">&nbsp;</td>
                <td width="30" height="30" valign="middle"><img src="grafika/strelicadole.png" width="24" height="24" /></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="1"></td>
          </tr>
          <tr>
            <td align="center" valign="top">&nbsp;</td>
          </tr>
        </table>
        <p>&nbsp;</p></td>
        <td width="690" align="right" valign="top"><table width="685" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td bgcolor="#002E5F"></td>
            <td height="1" bgcolor="#002E5F"></td>
            <td bgcolor="#002E5F"></td>
          </tr>
          <tr>
            <td width="1" bgcolor="#002E5F"></td>
            <td height="29" bgcolor="#002E5F" class="kontaktpocetna">&nbsp;</td>
            <td width="1" bgcolor="#002E5F"></td>
          </tr>
          <tr>
            <td width="1" bgcolor="#DCDCDC"></td>
            <td height="1"></td>
            <td width="1" bgcolor="#DCDCDC"></td>
          </tr>
          <tr>
            <td width="1" bgcolor="#DCDCDC"></td>
            <td height="299" align="center" valign="top"><table width="665" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="1" bgcolor="#E3E1D8"></td>
              </tr>
              <tr>
                <td height="20">&nbsp;</td>
              </tr>
              <tr>
                <td height="20"><table width="665" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="122" valign="top"><table width="122" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="20" class="datumi">Upišite komentar</td>
                      </tr>
                      <tr>
                        <td height="20">&nbsp;</td>
                      </tr>
                    </table></td>
                    <td height="20" align="left" valign="top"><form action="insertkoment.php" method="post" name="form1" id="form1">
                      <table width="423" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td height="20" class="komentlabeletext">Nadimak*:</td>
                        </tr>
                        <tr>
                          <td height="20"><input name="nickname" type="text" class="komentforma" id="nickname" /></td>
                        </tr>
                        <tr>
                          <td height="20" class="komentlabeletext">E-mail:</td>
                        </tr>
                        <tr>
                          <td height="20"><input name="email" type="text" class="komentforma" id="email" /></td>
                        </tr>
                        <tr>
                          <td height="20" class="komentlabeletext">Komentar*:</td>
                        </tr>
                        <tr>
                          <td height="20"><textarea name="opis" cols="45" rows="5" class="kontaktformatext" id="opis"></textarea></td>
                        </tr>
                        <tr>
                          <td height="10"></td>
                        </tr>
                        <tr>
                          <td height="20"><input name="Submit" type="submit" class="dugme" value="Spasi" /></td>
                        </tr>
                      </table>
                    </form></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="10"></td>
              </tr>
              <tr>
                <td height="1" bgcolor="#E3E1D8"></td>
              </tr>
              <tr>
                <td height="10"></td>
              </tr>
              <tr>
                <td height="20"><table width="665" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="122" height="25" bgcolor="#EDEFF4" class="cvtextplavispace">Nadimak</td>
                    <td height="25" bgcolor="#EDEFF4" class="cvtextplavi">Komentar</td>
                    <td width="100" height="25" bgcolor="#EDEFF4" class="cvtextplavi">Datum objave</td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="20"><?php include("konekcija.php");?>
                  <?php
// Retrieve data from database 
$sql="SELECT nickname,opis,datum_objave,vrijeme FROM tabela WHERE kategorija='nesto' order by id DESC";
$result=mysql_query($sql);
// Define $color=1
$color="1";
 
echo '<table width="665" border="0" align="center" cellpadding="0" cellspacing="1">';
while($rows=mysql_fetch_array($result)){
// If $color==1 table row color = #FFFFFF
if($color==1){
echo "<tr height='50' bgcolor='#FFFFFF'>
<td width='120' align='left' valign='top' class='nickkoment'>".$rows['nickname']."</td>
<td width='' align='left' valign='middle' class='opiskoment'>".nl2br($rows['opis'])."</td>
<td width='100' align='left' valign='middle' class='datumkoment'>".$rows['datum_objave']." u <br>".$rows['vrijeme']."</br></td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr height='50' bgcolor='#FFFFFF'>
<td width='120' align='left' valign='top' class='nickkoment'>".$rows['nickname']."</td>
<td width='' align='left' valign='middle' class='opiskoment'>".nl2br($rows['opis'])."</td>
<td width='100' align='left' valign='middle' class='datumkoment'>".$rows['datum_objave']." u <br>".$rows['vrijeme']."</br></td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
mysql_close();
?></td>
              </tr>
              <tr>
                <td height="20"><table width="665" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="1" height="20"></td>
                    <td width="120" height="20" align="left" valign="middle" bgcolor="#002E5F" class="sumaodluka">Σ</td>
                    <td width="1" height="20" align="left" valign="middle"></td>
                    <td height="20" align="left" valign="middle" bgcolor="#002E5F" class="sumaodluka">Ukupan broj komentara:</td>
                    <td width="1" height="20" align="left" valign="middle" bgcolor="#FFFFFF"></td>
                    <td width="100" height="20" align="left" valign="middle" bgcolor="#002E5F" class="tabheader"><span class="sumaodluka">
                      <?php 
include("konekcija.php");
// Retrieve data from database 
$result = mysql_query("SELECT * FROM tabela WHERE kategorija='nesto' ");
$num_rows = mysql_num_rows($result);
echo $num_rows;
?>
                    </span></td>
                    <td width="1" height="20" align="left" valign="middle"></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="20">&nbsp;</td>
              </tr>
            </table></td>
            <td width="1" bgcolor="#DCDCDC"></td>
          </tr>
          <tr>
            <td bgcolor="#DCDCDC"></td>
            <td height="1" bgcolor="#DCDCDC"></td>
            <td bgcolor="#DCDCDC"></td>
          </tr>
        </table></td>
      </tr>
    </table>


Code:
 ovo je insertcoment.php
<?php
include('konekcija.php');
// Get values from form 
$kategorija = $_POST['kategorija'];
$nickname = $_POST['nickname'];
$email = $_POST['email'];
$opis = $_POST['opis'];
$date = date("d.m.Y.");
// Insert data into mysql 
$sql ="INSERT INTO tabela (nickname,email,opis,datum_objave) VALUES ('$nickname', '$email', '$opis', '$date')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result) {
echo "Uspješno ste upisali komentar";
echo "<BR>";
echo "<a href='tvoj link'>Vratite se na stranicu sa komentarima</a>";
}
else {
echo "Greška pri upisu komentara u bazu";
}
// close connection
mysql_close();
?>


Meni radi super, samo bi trebao dodati jos zaštitu pri upisu u bazu, da ti neki bot robot ne nasurfa i ne zakuca bazu glupostima.
damaki
 
Odgovor na temu

[es] :: PHP :: Komentari text-a na web site-u

Strane: 1 2

[ Pregleda: 4313 | Odgovora: 20 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.