Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/01/2011, 00:30
Arcana
 
Fecha de Ingreso: mayo-2010
Mensajes: 185
Antigüedad: 14 años
Puntos: 2
Problema: Inserta campos en blanco

Hola, quiero poner un sistema de comentarios en mi index, pero mi problema es q cuando entran al index, añade un comentario en blanco a la base de datos, este es mi codigo:

Código PHP:
<?php

$conexion 
mysql_connect("sql201.byethost15.com""user""pass");
mysql_select_db("b15_5229524_estacion"$conexion);

$queEmp "SELECT * FROM Discos ORDER BY id DESC"
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
$totEmp mysql_num_rows($resEmp);
 if (
$totEmp0) {
    while (
$rowEmp mysql_fetch_assoc($resEmp)) {
 
    }
}
?>
<? 
    
if (nombre==""){
    echo 
"Debes rellenar todos los campos"; }
    else {      
    
$que "INSERT INTO firmas (nombre, comentario) ";  
    
$que.= "VALUES ('".$_POST['nick']."', '".$_POST['comentario']."')";  
    
$res mysql_query($que$conexion) or die(mysql_error());  
    
$state true;  
}
        
?>
        <?php  



if ($state) {  
echo 
"<p /><em>Comentario agregado</em></p>";  



?>
<?
// maximo por pagina 
$limit 25
 
// pagina pedida 
$pag = (int) $_GET["pag"]; 
if (
$pag 1

   
$pag 1

$offset = ($pag-1) * $limit
 
 
$sql "SELECT SQL_CALC_FOUND_ROWS nombre, comentario FROM firmas LIMIT $offset, $limit"
$sqlTotal "SELECT FOUND_ROWS() as total"
 
$rs mysql_query($sql); 
$rsTotal mysql_query($sqlTotal); 
 
$rowTotal mysql_fetch_assoc($rsTotal); 
// Total de registros sin limit 
$total $rowTotal["total"]; 
 
?>
<table border="1" bordercolor="#000"> 
   <thead> 
      <tr> 
         <td><b>Id</b></td> 
         <td><strong>Nick</strong></td> 
         <td><strong>Comentario</strong></td>
      </tr> 
   </thead> 
   <tbody> 
      
<?php 
         
while ($row mysql_fetch_assoc($rs)) 
         { 
            
$id $row["id"]; 
            
$name htmlentities($row["nombre"]);
            
$comentario $row["comentario"]; 
         
?>
 
         <tr> 
            <td>
<?php echo $id?></td> 
            <td>
<?php echo $name?></td> 
            <td><?php echo $comentario?></td>
         </tr> 
         
<?php 
         

      
?>
   </tbody> 
   <tfoot> 
      <tr> 
         <td colspan="3"> 
      
<?php 
         $totalPag 
ceil($total/$limit); 
         
$links = array(); 
         for( 
$i=1$i<=$totalPag $i++) 
         { 
            
$links[] = "<a href=\"?pag=$i\">$i</a>";  
         } 
         echo 
implode(" - "$links); 
      
?>         </td> 
      </tr>
   </tfoot> 
</table>
</p>
          <p><strong>Añade el Tuyo!</strong></p>
          <form id="form1" name="form1" method="post" action="">
            Nick
            <label>
              <input type="text" name="nick" id="textfield" />
              <br />
              Mensaje:<br />
            </label>
            <p>
              <label>
              <textarea name="comentario" id="textarea" cols="45" rows="5"></textarea>
              </label>
            </p>
            <p>
              <label>
              <input type="submit" name="button" id="button" value="Enviar mensaje" />
              <input type="hidden" name="action" value="add" />
              </label>
            </p>
          </form>