Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

manoaj

[Resolvido] Sistema de comentarios

Recommended Posts

pessoal alguem pode me explicar detalhadamente se possivel com exemplos ou se tiverem um tuto também serve , como eu faço para colocar um sistema de comentarios que apareça depois de cada posagem no meu site por exemplo eu tenho esse codigo que exibe as postagems agora como faço para que apareça a caixa de comentario apos cada postagem dessa e também os comentarios que são exibidos sejam relativos a postagem. ou seja o comentario da postagem 1 seja exibido so na postagem 1,

 

 

resumindo tudo como por um sistema de comentarios nesse codigo que exibi minhas postagens..

 

<div id="conteudo">
 <?php do { ?>
   <table  border="0" cellpadding="0" cellspacing="0" id="tableconte">
     <tr>
       <td height="38">Titulo:<?php echo $row_exibihome['titulo_home']; ?></td>
     </tr>
     <tr>
       <td height="49"><?php echo $row_exibihome['post_home']; ?></td>
     </tr>
     <tr>
       <td height="41">Autor: <?php echo $row_exibihome['autor_home']; ?>  Data:<?php echo $row_exibihome['data']; ?></td>
     </tr>
   </table>
   <?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)); ?>
 <table border="0">
   <tr>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, 0, $queryString_exibihome); ?>"><img src="images/First.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, max(0, $pageNum_exibihome - 1), $queryString_exibihome); ?>"><img src="images/Previous1.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, min($totalPages_exibihome, $pageNum_exibihome + 1), $queryString_exibihome); ?>"><img src="images/Next1.png" /></a>
         <?php } // Show if not last page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, $totalPages_exibihome, $queryString_exibihome); ?>"><img src="images/Last.png" /></a>
         <?php } // Show if not last page ?></td>
   </tr>
 </table>
</div><!--fim conteudo-->

Compartilhar este post


Link para o post
Compartilhar em outros sites

Uma maneira é.

 

Criar uma tabela "comentarios" no seu BD, e nesta tabela voce vai guardar as informações sobre o comentario, e a referencia a qual post ele pertence. Então quando exibir sua postagem voce pega do banco todos os comentarios que tenham o mesmo ID da postagem, aglo mais ou menos assim:

CREATE TABLE comentarios(
id int
id_postagem int
menssagem varchar
)

Claro que voce pode melhorar esta tabela, foi so como exemplo, mas entao, o "id" é o id do comentario, o "id_postagem" é o id da postagem onde o comentario foi feito e a "menssagem" é a menssagem que a pessoa escreveu.

 

Quanto ao formulario, voce coloca ele na sua pagina de postagem.

 

Espero que isso possa te guiar e te dar uma noção basica da ideia de como fazer.

 

 

flws

Compartilhar este post


Link para o post
Compartilhar em outros sites

sim quanto aquestão do relacionamento sim agora o negocio e por o formulario pra repetir depois de cada postagem

Compartilhar este post


Link para o post
Compartilhar em outros sites

pessoal da uma luz ai preciso muito contruir este sistema mas nao sei como começar pq só acho sistemas prontos e nao quero pronto quero construir um pra poder colocar no site só falta isso pra terminar o trabalho meu professor falo que eu tenho que contrir todo ele e nao usar nenhum codigo pronto!

Compartilhar este post


Link para o post
Compartilhar em outros sites

  1. Crie uma tabela, tipo comentarios:
    CREATE TABLE  `comentarios` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `nome_do_usuario` VARCHAR( 255 ) NOT NULL ,
    `id_da_postagem` VARCHAR( 255 ) NOT NULL ,
    `comentario` TEXT NOT NULL ,
    PRIMARY KEY (  `id` )
    )

  2. Agora vamos inserir comentários nessa tabela e no campo id, vamos colocar o id da notícia através de um $_GET['id']:
    <form method="post">
    <input type="text" name="nome" placeholder="Nome"><br>
    <textarea name="comentario" placeholder="Comentário"></textarea><br>
    <input type="submit" name="comentar" value="Comentar">
    </form>

    Agora o PHP:

    /* Definindo os valores das variáveis */
    $nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
    $comentario = $_POST['comentario'];
    $id_da_postagem = $_GET['id'];/* Pegamos o id da postagem */
    
    if($_POST['comentar']){
    
    $sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */
    
    $query = mysql_query($sql);/* Inserindo */
    
    if($query){
    echo "Comentado com sucesso!";
    }else{
    echo "Falha ao comentar";
    }
    
    }
    

  3. Agora vamos exibir os comentários:
    $id = $_GET['id'];/* Pega o id da postagem */
    
    $sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
    $query = mysql_query($sql);/* Seleciona */
    
    /* Hora de exibir via mysql_fetch_array() */
    while($info = mysql_fetch_array($query)){
    
    $nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
    $comentario = $info['comentario'];/* Comentário */
    
    echo "<b>".$nome_do_usuario."<br>";
    echo $comentario;
    
    }


Prontinho :grin:

Compartilhar este post


Link para o post
Compartilhar em outros sites

  1. Crie uma tabela, tipo comentarios:
    CREATE TABLE  `comentarios` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `nome_do_usuario` VARCHAR( 255 ) NOT NULL ,
    `id_da_postagem` VARCHAR( 255 ) NOT NULL ,
    `comentario` TEXT NOT NULL ,
    PRIMARY KEY (  `id` )
    )

  2. Agora vamos inserir comentários nessa tabela e no campo id, vamos colocar o id da notícia através de um $_GET['id']:
    <form method="post">
    <input type="text" name="nome" placeholder="Nome"><br>
    <textarea name="comentario" placeholder="Comentário"></textarea><br>
    <input type="submit" name="comentar" value="Comentar">
    </form>

    Agora o PHP:

    /* Definindo os valores das variáveis */
    $nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
    $comentario = $_POST['comentario'];
    $id_da_postagem = $_GET['id'];/* Pegamos o id da postagem */
    
    if($_POST['comentar']){
    
    $sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */
    
    $query = mysql_query($sql);/* Inserindo */
    
    if($query){
    echo "Comentado com sucesso!";
    }else{
    echo "Falha ao comentar";
    }
    
    }
    

  3. Agora vamos exibir os comentários:
    $id = $_GET['id'];/* Pega o id da postagem */
    
    $sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
    $query = mysql_query($sql);/* Seleciona */
    
    /* Hora de exibir via mysql_fetch_array() */
    while($info = mysql_fetch_array($query)){
    
    $nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
    $comentario = $info['comentario'];/* Comentário */
    
    echo "<b>".$nome_do_usuario."<br>";
    echo $comentario;
    
    }


Prontinho :grin:

cara muito orbigado mesmo não precisva ter feito so explicado mas vo ler todo codigo com calma pra saber explica pra ele muito obrigado mesmo me salvo tamara que tudo certinho aqui posto noticias brogadao manin:D

 

( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: id in C:\wamp\www\home.php on line 163

Call Stack

# Time Memory Function Location

1 0.0021 423336 {main}( ) ..\home.php:0

 

 

 

( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: nome in C:\wamp\www\home.php on line 187

Call Stack

# Time Memory Function Location

1 0.0021 423336 {main}( ) ..\home.php:0

 

( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: comentario in C:\wamp\www\home.php on line 188

Call Stack

# Time Memory Function Location

1 0.0021 423336 {main}( ) ..\home.php:0

 

( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: id in C:\wamp\www\home.php on line 189

Call Stack

# Time Memory Function Location

1 0.0021 423336 {main}( ) ..\home.php:0

 

( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: comentar in C:\wamp\www\home.php on line 191

Call Stack

# Time Memory Function Location

1 0.0021 423336 {main}( ) ..\home.php:0

 

 

deu esses erros ai o comentarios sao feitos pelos visitantantes eu acho que eu que fiz errado na hoora de implementar o teu codigo la eua ind nao puxei o id da uma explicada pra mim como funciona o sistema de postagem dos comentarios nesse teu sistema

 

coloquie assim mas acho que tenho que fazer o id da posatgem ser ezibida na url pro sistema de comentario puxar o id?

 

<div id="conteudo">
 <?php do { ?>
   <table  border="0" cellpadding="0" cellspacing="0" id="tableconte">
     <tr>
       <td height="38">Titulo:<?php echo $row_exibihome['titulo_home']; ?></td>
     </tr>
     <tr>
       <td height="49"><?php echo $row_exibihome['post_home']; ?></td>
     </tr>
     <tr>
       <td height="41">Autor: <?php echo $row_exibihome['autor_home']; ?>  Data:<?php echo $row_exibihome['data']; ?></td>
     </tr>
   </table>
   <?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)); ?>
 <table border="0">
   <tr>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, 0, $queryString_exibihome); ?>"><img src="images/First.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, max(0, $pageNum_exibihome - 1), $queryString_exibihome); ?>"><img src="images/Previous1.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, min($totalPages_exibihome, $pageNum_exibihome + 1), $queryString_exibihome); ?>"><img src="images/Next1.png" /></a>
         <?php } // Show if not last page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, $totalPages_exibihome, $queryString_exibihome); ?>"><img src="images/Last.png" /></a>
         <?php } // Show if not last page ?></td>
   </tr>
 </table>
 <?php
 $id = $_GET['id'];/* Pega o id da postagem */

$sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
$query = mysql_query($sql);/* Seleciona */

/* Hora de exibir via mysql_fetch_array() */
while($info = mysql_fetch_array($query)){

$nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
$comentario = $info['comentario'];/* Comentário */

echo "<b>".$nome_do_usuario."<br>";
echo $comentario;

}
 ?>

<form method="post">
<input type="text" name="nome" placeholder="Nome"><br>
<textarea name="comentario" placeholder="Comentário"></textarea><br>
<input type="submit" name="comentar" value="Comentar">
</form>

<?php
/* Definindo os valores das variáveis */
$nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
$comentario = $_POST['comentario'];
$id_da_postagem = $_GET['id'];/* Pegamos o id da postagem */

if($_POST['comentar']){

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */

$query = mysql_query($sql);/* Inserindo */

if($query){
echo "Comentado com sucesso!";
}else{
echo "Falha ao comentar";
}

}
?>
</div><!--fim conteudo-->

 

vo postar todo codigo assim achoq ue fica melhor ocompreendimento

 

<?php require('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_exibihome = 1;
$pageNum_exibihome = 0;
if (isset($_GET['pageNum_exibihome'])) {
 $pageNum_exibihome = $_GET['pageNum_exibihome'];
}
$startRow_exibihome = $pageNum_exibihome * $maxRows_exibihome;

mysql_select_db($database_config, $config);
$query_exibihome = "SELECT * FROM home";
$query_limit_exibihome = sprintf("%s LIMIT %d, %d", $query_exibihome, $startRow_exibihome, $maxRows_exibihome);
$exibihome = mysql_query($query_limit_exibihome, $config) or die(mysql_error());
$row_exibihome = mysql_fetch_assoc($exibihome);

if (isset($_GET['totalRows_exibihome'])) {
 $totalRows_exibihome = $_GET['totalRows_exibihome'];
} else {
 $all_exibihome = mysql_query($query_exibihome);
 $totalRows_exibihome = mysql_num_rows($all_exibihome);
}
$totalPages_exibihome = ceil($totalRows_exibihome/$maxRows_exibihome)-1;

$queryString_exibihome = "";
if (!empty($_SERVER['QUERY_STRING'])) {
 $params = explode("&", $_SERVER['QUERY_STRING']);
 $newParams = array();
 foreach ($params as $param) {
   if (stristr($param, "pageNum_exibihome") == false && 
       stristr($param, "totalRows_exibihome") == false) {
     array_push($newParams, $param);
   }
 }
 if (count($newParams) != 0) {
   $queryString_exibihome = "&" . htmlentities(implode("&", $newParams));
 }
}
$queryString_exibihome = sprintf("&totalRows_exibihome=%d%s", $totalRows_exibihome, $queryString_exibihome);
?>
<!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>Documento sem título</title>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon.png" />
   <link rel="stylesheet" href="css/default/default.css" type="text/css" media="screen" />
   <link rel="stylesheet" href="css/nivo-slider.css" type="text/css" media="screen" />

    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
   <script type="text/javascript" src="js/jquery.nivo.slider.js"></script>
   <script type="text/javascript">
   $(window).load(function() {
       $('#slider').nivoSlider();
   });
   </script>
</head>

<body>
<div id="topo">
 <table id="topota" border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td height="388" align="center">
     <div id="wrapper">
       <div class="slider-wrapper theme-default">
           <div id="slider" class="nivoSlider">
               <img src="fotos/slide.png" data-thumb="images/toystory.jpg" alt="" />
               <img src="fotos/slide1.png" data-thumb="images/up.jpg" alt="" title="" />
               <img src="fotos/slide2.png" data-thumb="images/walle.jpg" alt="" data-transition="slideInLeft" />
               <img src="fotos/slide3.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide4.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide5.png" data-thumb="images/nemo.jpg" alt="" title="" />
           </div>
           <div id="htmlcaption" class="nivo-html-caption">
               <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>. 
           </div>
       </div>

   </div>
   </td>
   </tr>
   <tr>
     <td align="center">
    <div  id="top"><ul>
           <li  class="selected" ><a href="home.php">Airton Junior</a></li>
           <li  ><a href="agenda.php">Agenda</a></li>
           <li  ><a href="artigos.php">Artigos</a></li>
           <li  ><a href="gale.php">Galeria</a></li>
           <!--<li  ><a href="planos.php">Planos</a></li>-->
           <li  ><a href="ministerio.php">Ministério</a></li>
           <li  ><a href="contato.php">Contato</a></li>
       </ul></div>
       </td>
   </tr>
 </table>

</div><!--fim topo-->

<div id="conteudo">
 <?php do { ?>
   <table  border="0" cellpadding="0" cellspacing="0" id="tableconte">
     <tr>
       <td height="38">Titulo:<?php echo $row_exibihome['titulo_home']; ?></td>
     </tr>
     <tr>
       <td height="49"><?php echo $row_exibihome['post_home']; ?></td>
     </tr>
     <tr>
       <td height="41">Autor: <?php echo $row_exibihome['autor_home']; ?>  Data:<?php echo $row_exibihome['data']; ?></td>
     </tr>
   </table>
   <?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)); ?>
 <table border="0">
   <tr>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, 0, $queryString_exibihome); ?>"><img src="images/First.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, max(0, $pageNum_exibihome - 1), $queryString_exibihome); ?>"><img src="images/Previous1.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, min($totalPages_exibihome, $pageNum_exibihome + 1), $queryString_exibihome); ?>"><img src="images/Next1.png" /></a>
         <?php } // Show if not last page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, $totalPages_exibihome, $queryString_exibihome); ?>"><img src="images/Last.png" /></a>
         <?php } // Show if not last page ?></td>
   </tr>
 </table>
 <?php
 $id = $_GET['id'];/* Pega o id da postagem */

$sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
$query = mysql_query($sql);/* Seleciona */

/* Hora de exibir via mysql_fetch_array() */
while($info = mysql_fetch_array($query)){

$nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
$comentario = $info['comentario'];/* Comentário */

echo "<b>".$nome_do_usuario."<br>";
echo $comentario;

}
 ?>

<form method="post">
<input type="text" name="nome" placeholder="Nome"><br>
<textarea name="comentario" placeholder="Comentário"></textarea><br>
<input type="submit" name="comentar" value="Comentar">
</form>

<?php
/* Definindo os valores das variáveis */
$nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
$comentario = $_POST['comentario'];
$id_da_postagem = $_GET['id'];/* Pegamos o id da postagem */

if($_POST['comentar']){

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */

$query = mysql_query($sql);/* Inserindo */

if($query){
echo "Comentado com sucesso!";
}else{
echo "Falha ao comentar";
}

}
?>
</div><!--fim conteudo-->

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você precisa ter uma postagem e entra no site, tipo: seu-site.com/postagem.php?id=id-da-postagem

ou fazer um SELECT e pegar o id e colocar no WHERE do SELECT de comentários.

Esses são erros comuns, como por exemplo, esse: ( ! ) Notice: Undefined index: comentar in C:\wamp\www\home.php on line 191

Significa que você não clicou no botão comentar ainda.

Se não quiser exibir esses erros:

ini_set( 'display_errors', 0 );//Ocultando error nas páginas

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você precisa ter uma postagem e entra no site, tipo: seu-site.com/postagem.php?id=id-da-postagem

ou fazer um SELECT e pegar o id e colocar no WHERE do SELECT de comentários.

hum entao o jeito que coloquei nao ta errado o que falta pra queles erros desaparecerem é só fazer um select da postagem pra que o id apareça na url? tipo a minha postagem ja ta sendo exibida por um meio sem o select onde eolocaria ele pra que nao interferice no restante ou para que seja exibido corretamente?

 

no caso eu já fiz um select já na pagina que é este que é responsavel por exibir as noticias olha

 

mysql_select_db($database_config, $config);
$query_exibihome = "SELECT * FROM home";
$query_limit_exibihome = sprintf("%s LIMIT %d, %d", $query_exibihome, $startRow_exibihome, $maxRows_exibihome);
$exibihome = mysql_query($query_limit_exibihome, $config) or die(mysql_error());
$row_exibihome = mysql_fetch_assoc($exibihome);

 

agora falta oque?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ai você faria mais ou menos assim:

Criaria um while pro mysql_fetch_assoc e dentro o sistema de comentário e troque tudo que estiver escrito $_GET['id'] por $row_exibihome['id']:

mysql_select_db($database_config, $config);
$query_exibihome = "SELECT * FROM home";
$query_limit_exibihome = sprintf("%s LIMIT %d, %d", $query_exibihome, $startRow_exibihome, $maxRows_exibihome);
$exibihome = mysql_query($query_limit_exibihome, $config) or die(mysql_error());
while($row_exibihome = mysql_fetch_assoc($exibihome)){

/* Código do sistema de comentários */

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz o que você falo olha mas continua sem funcionar quando vo postar retorna o erro que você colocou falha ao comentar

 

como ficou

 

<?php 
ini_set( 'display_errors', 0 );//Ocultando error nas páginas
require('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_exibihome = 1;
$pageNum_exibihome = 0;
if (isset($_GET['pageNum_exibihome'])) {
 $pageNum_exibihome = $_GET['pageNum_exibihome'];
}
$startRow_exibihome = $pageNum_exibihome * $maxRows_exibihome;

mysql_select_db($database_config, $config);
$query_exibihome = "SELECT * FROM home";
$query_limit_exibihome = sprintf("%s LIMIT %d, %d", $query_exibihome, $startRow_exibihome, $maxRows_exibihome);
$exibihome = mysql_query($query_limit_exibihome, $config) or die(mysql_error());
while($row_exibihome = mysql_fetch_assoc($exibihome))

if (isset($_GET['totalRows_exibihome'])) {
 $totalRows_exibihome = $_GET['totalRows_exibihome'];
} else {
 $all_exibihome = mysql_query($query_exibihome);
 $totalRows_exibihome = mysql_num_rows($all_exibihome);
}
$totalPages_exibihome = ceil($totalRows_exibihome/$maxRows_exibihome)-1;

$queryString_exibihome = "";
if (!empty($_SERVER['QUERY_STRING'])) {
 $params = explode("&", $_SERVER['QUERY_STRING']);
 $newParams = array();
 foreach ($params as $param) {
   if (stristr($param, "pageNum_exibihome") == false && 
       stristr($param, "totalRows_exibihome") == false) {
     array_push($newParams, $param);
   }
 }
 if (count($newParams) != 0) {
   $queryString_exibihome = "&" . htmlentities(implode("&", $newParams));
 }
}
$queryString_exibihome = sprintf("&totalRows_exibihome=%d%s", $totalRows_exibihome, $queryString_exibihome);
?>
<!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>Documento sem título</title>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon.png" />
   <link rel="stylesheet" href="css/default/default.css" type="text/css" media="screen" />
   <link rel="stylesheet" href="css/nivo-slider.css" type="text/css" media="screen" />

    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
   <script type="text/javascript" src="js/jquery.nivo.slider.js"></script>
   <script type="text/javascript">
   $(window).load(function() {
       $('#slider').nivoSlider();
   });
   </script>
</head>

<body>
<div id="topo">
 <table id="topota" border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td height="388" align="center">
     <div id="wrapper">
       <div class="slider-wrapper theme-default">
           <div id="slider" class="nivoSlider">
               <img src="fotos/slide.png" data-thumb="images/toystory.jpg" alt="" />
               <img src="fotos/slide1.png" data-thumb="images/up.jpg" alt="" title="" />
               <img src="fotos/slide2.png" data-thumb="images/walle.jpg" alt="" data-transition="slideInLeft" />
               <img src="fotos/slide3.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide4.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide5.png" data-thumb="images/nemo.jpg" alt="" title="" />
           </div>
           <div id="htmlcaption" class="nivo-html-caption">
               <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>. 
           </div>
       </div>

   </div>
   </td>
   </tr>
   <tr>
     <td align="center">
    <div  id="top"><ul>
           <li  class="selected" ><a href="home.php">Airton Junior</a></li>
           <li  ><a href="agenda.php">Agenda</a></li>
           <li  ><a href="artigos.php">Artigos</a></li>
           <li  ><a href="gale.php">Galeria</a></li>
           <!--<li  ><a href="planos.php">Planos</a></li>-->
           <li  ><a href="ministerio.php">Ministério</a></li>
           <li  ><a href="contato.php">Contato</a></li>
       </ul></div>
       </td>
   </tr>
 </table>

</div><!--fim topo-->

<div id="conteudo">
 <?php do { ?>
   <table  border="0" cellpadding="0" cellspacing="0" id="tableconte">
     <tr>
       <td height="38">Titulo:<?php echo $row_exibihome['titulo_home']; ?></td>
     </tr>
     <tr>
       <td height="49"><?php echo $row_exibihome['post_home']; ?></td>
     </tr>
     <tr>
       <td height="41">Autor: <?php echo $row_exibihome['autor_home']; ?>  Data:<?php echo $row_exibihome['data']; ?></td>
     </tr>
   </table>
   <?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)); ?>
 <table border="0">
   <tr>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, 0, $queryString_exibihome); ?>"><img src="images/First.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, max(0, $pageNum_exibihome - 1), $queryString_exibihome); ?>"><img src="images/Previous1.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, min($totalPages_exibihome, $pageNum_exibihome + 1), $queryString_exibihome); ?>"><img src="images/Next1.png" /></a>
         <?php } // Show if not last page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, $totalPages_exibihome, $queryString_exibihome); ?>"><img src="images/Last.png" /></a>
         <?php } // Show if not last page ?></td>
   </tr>
 </table>
 <?php
 $id = $row_exibihome['id'];/* Pega o id da postagem */

$sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
$query = mysql_query($sql);/* Seleciona */

/* Hora de exibir via mysql_fetch_array() */
while($info = mysql_fetch_array($query)){

$nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
$comentario = $info['comentario'];/* Comentário */

echo "<b>".$nome_do_usuario."<br>";
echo $comentario;

}
 ?>

<form method="post">
<input type="text" name="nome" placeholder="Nome"><br>
<textarea name="comentario" placeholder="Comentário"></textarea><br>
<input type="submit" name="comentar" value="Comentar">
</form>

<?php
/* Definindo os valores das variáveis */
$nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
$comentario = $_POST['comentario'];
$id_da_postagem = $row_exibihome['id'];/* Pegamos o id da postagem */

if($_POST['comentar']){

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */

$query = mysql_query($sql);/* Inserindo */

if($query){
echo "Comentado com sucesso!";
}else{
echo "Falha ao comentar";
}

}
?>
</div><!--fim conteudo-->

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente assim:

<?php 
ini_set( 'display_errors', 0 );//Ocultando error nas páginas
require('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_exibihome = 1;
$pageNum_exibihome = 0;
if (isset($_GET['pageNum_exibihome'])) {
 $pageNum_exibihome = $_GET['pageNum_exibihome'];
}
$startRow_exibihome = $pageNum_exibihome * $maxRows_exibihome;

mysql_select_db($database_config, $config);
$query_exibihome = "SELECT * FROM home";
$query_limit_exibihome = sprintf("%s LIMIT %d, %d", $query_exibihome, $startRow_exibihome, $maxRows_exibihome);
$exibihome = mysql_query($query_limit_exibihome, $config) or die(mysql_error());
while($row_exibihome = mysql_fetch_assoc($exibihome))

if (isset($_GET['totalRows_exibihome'])) {
 $totalRows_exibihome = $_GET['totalRows_exibihome'];
} else {
 $all_exibihome = mysql_query($query_exibihome);
 $totalRows_exibihome = mysql_num_rows($all_exibihome);
}
$totalPages_exibihome = ceil($totalRows_exibihome/$maxRows_exibihome)-1;

$queryString_exibihome = "";
if (!empty($_SERVER['QUERY_STRING'])) {
 $params = explode("&", $_SERVER['QUERY_STRING']);
 $newParams = array();
 foreach ($params as $param) {
   if (stristr($param, "pageNum_exibihome") == false && 
       stristr($param, "totalRows_exibihome") == false) {
     array_push($newParams, $param);
   }
 }
 if (count($newParams) != 0) {
   $queryString_exibihome = "&" . htmlentities(implode("&", $newParams));
 }
}
$queryString_exibihome = sprintf("&totalRows_exibihome=%d%s", $totalRows_exibihome, $queryString_exibihome);
?>
<!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>Documento sem título</title>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="images/favicon.png" />
   <link rel="stylesheet" href="css/default/default.css" type="text/css" media="screen" />
   <link rel="stylesheet" href="css/nivo-slider.css" type="text/css" media="screen" />

    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
   <script type="text/javascript" src="js/jquery.nivo.slider.js"></script>
   <script type="text/javascript">
   $(window).load(function() {
       $('#slider').nivoSlider();
   });
   </script>
</head>

<body>
<div id="topo">
 <table id="topota" border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td height="388" align="center">
     <div id="wrapper">
       <div class="slider-wrapper theme-default">
           <div id="slider" class="nivoSlider">
               <img src="fotos/slide.png" data-thumb="images/toystory.jpg" alt="" />
               <img src="fotos/slide1.png" data-thumb="images/up.jpg" alt="" title="" />
               <img src="fotos/slide2.png" data-thumb="images/walle.jpg" alt="" data-transition="slideInLeft" />
               <img src="fotos/slide3.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide4.png" data-thumb="images/nemo.jpg" alt="" title="" />
               <img src="fotos/slide5.png" data-thumb="images/nemo.jpg" alt="" title="" />
           </div>
           <div id="htmlcaption" class="nivo-html-caption">
               <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>. 
           </div>
       </div>

   </div>
   </td>
   </tr>
   <tr>
     <td align="center">
    <div  id="top"><ul>
           <li  class="selected" ><a href="home.php">Airton Junior</a></li>
           <li  ><a href="agenda.php">Agenda</a></li>
           <li  ><a href="artigos.php">Artigos</a></li>
           <li  ><a href="gale.php">Galeria</a></li>
           <!--<li  ><a href="planos.php">Planos</a></li>-->
           <li  ><a href="ministerio.php">Ministério</a></li>
           <li  ><a href="contato.php">Contato</a></li>
       </ul></div>
       </td>
   </tr>
 </table>

</div><!--fim topo-->

<div id="conteudo">
 <?php do { ?>
   <table  border="0" cellpadding="0" cellspacing="0" id="tableconte">
     <tr>
       <td height="38">Titulo:<?php echo $row_exibihome['titulo_home']; ?></td>
     </tr>
     <tr>
       <td height="49"><?php echo $row_exibihome['post_home']; ?></td>
     </tr>
     <tr>
       <td height="41">Autor: <?php echo $row_exibihome['autor_home']; ?>  Data:<?php echo $row_exibihome['data']; ?></td>
     </tr>
   </table>
   <?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)){ ?>
 <table border="0">
   <tr>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, 0, $queryString_exibihome); ?>"><img src="images/First.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome > 0) { // Show if not first page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, max(0, $pageNum_exibihome - 1), $queryString_exibihome); ?>"><img src="images/Previous1.png" /></a>
         <?php } // Show if not first page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, min($totalPages_exibihome, $pageNum_exibihome + 1), $queryString_exibihome); ?>"><img src="images/Next1.png" /></a>
         <?php } // Show if not last page ?></td>
     <td><?php if ($pageNum_exibihome < $totalPages_exibihome) { // Show if not last page ?>
         <a href="<?php printf("%s?pageNum_exibihome=%d%s", $currentPage, $totalPages_exibihome, $queryString_exibihome); ?>"><img src="images/Last.png" /></a>
         <?php } // Show if not last page ?></td>
   </tr>
 </table>
 <?php
 $id = $row_exibihome['id'];/* Pega o id da postagem */

$sql = "SELECT * FROM `comentarios` WHERE id = '$id'";/* SQL para selecionar */
$query = mysql_query($sql);/* Seleciona */

/* Hora de exibir via mysql_fetch_array() */
while($info = mysql_fetch_array($query)){

$nome_do_usuario = $info['nome_do_usuario'];/* Nome do usuário */
$comentario = $info['comentario'];/* Comentário */

echo "<b>".$nome_do_usuario."<br>";
echo $comentario;

}
 ?>

<form method="post">
<input type="text" name="nome" placeholder="Nome"><br>
<textarea name="comentario" placeholder="Comentário"></textarea><br>
<input type="submit" name="comentar" value="Comentar">
</form>

<?php
/* Definindo os valores das variáveis */
$nome_do_usuario = $_POST['nome'];/* Se já estiver numa session, substitua por ela */
$comentario = $_POST['comentario'];
$id_da_postagem = $row_exibihome['id'];/* Pegamos o id da postagem */
}
if($_POST['comentar']){

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ($nome_do_usuario, $id_da_postagem, $comentario)";/* SQL para inserir */

$query = mysql_query($sql);/* Inserindo */

if($query){
echo "Comentado com sucesso!";
}else{
echo "Falha ao comentar";
}

}
?>
</div><!--fim conteudo-->

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara o dream ta me retornando um erro na linha 147 correspondente a isto aqui

 

<?php } while ($row_exibihome = mysql_fetch_assoc($exibihome)){ ?>

 

 

nao eua cho que foi aberto ou fechado errado algum parametro mas não to sabendo qual só fala que o erro ta sendo causado ai nesta linha ,

quais as mudaçãs que você fez e onde?

 

dexa queto resolvi era a falta de um ; no final da linha ali kkkk vo testa agora..

 

continua com falha ao comentar mano ta complicado esse negocio em kkkk ele exibe o echo da falha e não posta!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Nossa, descobri um erro meu aqui, perdão, sério. Na linha da var $sql, esqueci de colocar entre aspas os valores.

Agora deu certo, fiz o teste aqui:

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ('$nome_do_usuario', '$id_da_postagem', '$comentario')";/* SQL para inserir */

Compartilhar este post


Link para o post
Compartilhar em outros sites

Nossa, descobri um erro meu aqui, perdão, sério. Na linha da var $sql, esqueci de colocar entre aspas os valores.

Agora deu certo, fiz o teste aqui:

$sql = "INSERT INTO `comentarios` (nome_do_usuario, id_da_postagem, comentario) VALUES ('$nome_do_usuario', '$id_da_postagem', '$comentario')";/* SQL para inserir */

kkkkkkkk mano brigadão mas depois de tanto sofrimento e com tua ajuda achei uma video aula e juntando com seu sistema que você fez conssegui monta tudo certinho brigado mesmo sem tua ajuda nao consseguiria vlw :D

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.