Comunidad de diseño web y desarrollo en internet online

Limitar firmas en libro de visitas..ayuda

Citar            
MensajeEscrito el 09 May 2007 12:29 am
Hola amigos, se me dio por hacer un libro de visitas en dreamwevaer, con php y mysql (phpmyadmin)........ yo a la entrada del comentario le puse repetir region solo 15 veces, porque esa es mi intencion...que el limite de firmas sea 15.... pero sin embargo, esto es visual..es decir, solo se van a ver 15, pero si siguen firmando, los comentarios se siguen acumulando en la base de datos...por ello queria saber si se puede desde dreamweaver o desde phpmyadmin establecer un limite de entradas y que cuando llegue al limites de 15 entradas no se pueda firmar mas mostrandose un mensaje que lo notifique..

se podra hacer esto? yo he visto que por ejemplo en los fotologs de terra hay limites para las firmas......bueno gracias!

Saludos!!

Por ramon_123

14 de clabLevel



 

msie
Citar            
MensajeEscrito el 09 May 2007 04:07 am
Haz una consulta en mySQL del numero de entradas que hay, al cargar la pagina. Si es mayor a 15, oculta el formulario de agregar entrada nueva.

Por Lunatic Lycanthrop

Claber

1203 de clabLevel

7 tutoriales

1 ejemplo

Genero:Masculino  

The dark places where wolves access internet with 46,6 kbps

firefox
Citar            
MensajeEscrito el 09 May 2007 04:20 pm
Muchas gracias por la respuesta! ...umm ahi se me complica un poco....como se haria esto? es que soy principiante con esto de php y sql....

bueno gracias muchas gracias!

Saludos!

Por ramon_123

14 de clabLevel



 

msie
Citar            
MensajeEscrito el 09 May 2007 04:59 pm
Para ello debes realizar una consulta contando cuantas filas hay en la tabla de tu libro de visitas, te daré un ejemplo para que tengas una idea:

Código :

<?php
   $query = mysql_query("SELECT * FROM tabla_libro");
   while($row = mysql_fetch_array($query)) {
   // muestras tus 15 firmas
      if(mysql_num_rows($query) == 15) { // preguntamos si el límite de firmas permitidas ya llegó a 15
?>
      El límite de firmas terminado.
<?php
      }else {
         // muestras el formulario para que firmen
   }
?>


Espero que ese ejemplo te podrá servir de ayuda, cualquier duda, nos la haces saber :)

Saludos.

Por MijT

97 de clabLevel

1 tutorial

 



Ultima edición por MijT el 09 May 2007 05:52 pm, editado 2 veces

Lima - Perú

firefox
Citar            
MensajeEscrito el 09 May 2007 05:45 pm
muchas gracias ahora voy entendiento..el tema es que nose como implementear eso a mi codigo... mira vamos a desmenuzarlo...
el code completo

Código :

<?php require_once('Connections/firmas.php'); ?>
<?php require_once('Connections/firmas.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO comentarios (Nombre, Url, Email, Comentario) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['Nombre'], "text"),
                       GetSQLValueString($_POST['Url'], "text"),
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['Comentario'], "text"));

  mysql_select_db($database_firmas, $firmas);
  $Result1 = mysql_query($insertSQL, $firmas) or die(mysql_error());

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO comentarios (Nombre, Url, Email, Comentario) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['Nombre'], "text"),
                       GetSQLValueString($_POST['Url'], "text"),
                       GetSQLValueString($_POST['Email'], "text"),
                       GetSQLValueString($_POST['Comentario'], "text"));

  mysql_select_db($database_firmas, $firmas);
  $Result1 = mysql_query($insertSQL, $firmas) or die(mysql_error());

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$maxRows_comentarios = 15;
$pageNum_comentarios = 0;
if (isset($_GET['pageNum_comentarios'])) {
  $pageNum_comentarios = $_GET['pageNum_comentarios'];
}
$startRow_comentarios = $pageNum_comentarios * $maxRows_comentarios;

mysql_select_db($database_firmas, $firmas);
$query_comentarios = "SELECT * FROM comentarios";
$query_limit_comentarios = sprintf("%s LIMIT %d, %d", $query_comentarios, $startRow_comentarios, $maxRows_comentarios);
$comentarios = mysql_query($query_limit_comentarios, $firmas) or die(mysql_error());
$row_comentarios = mysql_fetch_assoc($comentarios);

if (isset($_GET['totalRows_comentarios'])) {
  $totalRows_comentarios = $_GET['totalRows_comentarios'];
} else {
  $all_comentarios = mysql_query($query_comentarios);
  $totalRows_comentarios = mysql_num_rows($all_comentarios);
}
$totalPages_comentarios = ceil($totalRows_comentarios/$maxRows_comentarios)-1;
?>
<!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=iso-8859-1" />
<title>FIRMA!!</title>
<style type="text/css">
<!--
body {
   background-color: #999999;
}
.Estilo1 {
   font-size: 18px;
   font-weight: bold;
}
a:link {
   color: #FFFFFF;
}
-->
</style></head>
<body>
<table width="721" border="1" align="center">
  <tr>
    <td width="144">&nbsp;</td>
    <td width="411"><hr align="left" width="10" />
      <p align="left" class="Estilo1">aca estan las firmas, que copado.... </p>
      
      
      <div align="left">
        <table width="460" border="0" align="center">
          <?php do { ?>
            <tr>
              <td width="441"><p>Comentario de<strong> <?php echo $row_comentarios['Nombre']; ?></strong> <a href="mailto:<?php echo $row_comentarios['Email']; ?>">Email</a> <a href="<?php echo $row_comentarios['Url']; ?>">Url</a></p></td>
            </tr>
            <tr>
              <td height="21"><p><?php echo $row_comentarios['Comentario']; ?></p></td>
            </tr>
            <tr>
              <td height="21"><hr noshade="noshade" /></td>
            </tr>
            <?php } while ($row_comentarios = mysql_fetch_assoc($comentarios)); ?>
                                  </table>
      </div>
      <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        
        
        <div align="left">
          <table align="center">
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Nombre:</td>
              <td><input type="text" name="Nombre" value="" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Url:</td>
              <td><input type="text" name="Url" value="http://" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Email:</td>
              <td><input type="text" name="Email" value="" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td align="right" valign="top" nowrap="nowrap">Comentario:</td>
              <td><textarea name="Comentario" cols="50" rows="8"></textarea></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">&nbsp;</td>
              <td><input name="submit" type="submit" value="Post!" /></td>
            </tr>
                                                                              </table>
          <input type="hidden" name="MM_insert" value="form1" />
          </div>
      </form>      <p align="left">&nbsp;</p></td>
    <td width="144">&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($comentarios);
?>

Bueno, la parte que vos me estas diciendo se parece a esta

Código :

mysql_select_db($database_firmas, $firmas);
$query_comentarios = "SELECT * FROM comentarios";
$query_limit_comentarios = sprintf("%s LIMIT %d, %d", $query_comentarios, $startRow_comentarios, $maxRows_comentarios);
$comentarios = mysql_query($query_limit_comentarios, $firmas) or die(mysql_error());
$row_comentarios = mysql_fetch_assoc($comentarios);

Ahi veo que hay algo de las limitaciones de entradas..debe ser que yo estableci repetir region solo 15 veces...debe ser eso...
Aca tenemos el formulario de envio

Código :

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        
        
        <div align="left">
          <table align="center">
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Nombre:</td>
              <td><input type="text" name="Nombre" value="" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Url:</td>
              <td><input type="text" name="Url" value="http://" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Email:</td>
              <td><input type="text" name="Email" value="" size="50" /></td>
            </tr>
            <tr valign="baseline">
              <td align="right" valign="top" nowrap="nowrap">Comentario:</td>
              <td><textarea name="Comentario" cols="50" rows="8"></textarea></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">&nbsp;</td>
              <td><input name="submit" type="submit" value="Post!" /></td>
            </tr>
                                                                              </table>
          <input type="hidden" name="MM_insert" value="form1" />
          </div>
      </form>

y creo que nada mas, despues lo otro es configuracion que hay :) ...bueno es un avance para mi que soy principiante....identifique mas o menos las partes del code...pero la pregunta seria, como puedo adaptar el code que me pasaste a esto?...
Saludos y muchas gracias!!

Por ramon_123

14 de clabLevel



 

msie
Citar            
MensajeEscrito el 09 May 2007 07:06 pm
Pfff, lo que no me gusta del Dreamweaver es que crea código bastante engorroso, así que te hice uno más fácil de entender, espero que te sirva, el diseño ya lo puedes cambiar según tu página.

La tabla que creé es esta:

Código :

CREATE TABLE `book` (
  `id_book` int(5) NOT NULL auto_increment,
  `autor` varchar(30) NOT NULL default '',
  `fecha` datetime NOT NULL default '0000-00-00 00:00:00',
  `email` varchar(40) NOT NULL default '',
  `web` varchar(40) NOT NULL default '',
  `comentario` longtext NOT NULL,
  PRIMARY KEY  (`id_book`)
)


Este es el script:

Código :

<?php
   include('conex.php'); // este archivo contiene tus datos de conexión a mysql, puedes cambiarle el nombre por el tuyo
   if(isset($_POST['firma'])) {
   // con esta función validamos que el email ingresado sea correcto
   function email_valido($correo) {
        if ( eregi ( "^[_\.0-9a-z-]+@[0-9a-z\._\-]+\.[a-z]{2,4}$", $correo )) return true;
        else return false;
   }
      if($_POST['autor'] == '') {
         echo "No has ingresado tu nombre";
      }elseif(!email_valido($_POST['email'])) {
         echo "el email ingresado no es válido.";
      }elseif($_POST['comentario'] == '') {
         echo "No has ingresado tu mensaje";
      }else {
         // evitamos que se ingrese codigo malicioso en los campos
         $autor = stripslashes($_POST['autor']);
         $autor = strip_tags($autor);
         $email = stripslashes($_POST['email']);
         $email = strip_tags($email);
         $web = stripslashes($_POST['web']);
         $web = strip_tags($web);
         $comentario = stripslashes($_POST['comentario']);
         $comentario = strip_tags($comentario);
         // ingresamos los datos a la BD
         $query = mysql_query("INSERT INTO book (autor,fecha,email,web,comentario) VALUES('".$autor."',NOW(),'".$email."','".$web."','".$comentario."')");
         if($query) {
            echo "Datos ingresados con éxito";
         }else {
            echo "Error de registro";
         }
      }
   }else {
      $sql = mysql_query("SELECT * FROM book ORDER BY fecha DESC");
      // esta función la usaremos para cambiar el formato de la fecha
      function obtener_fecha_dmY($fecha) {
         $nombres_mes=array(1=>"Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sept", "Oct", "Nov", "Dic");
         
         $ano=substr($fecha,0,4);
         $mes=substr($fecha,5,2);
         $dia=substr($fecha,8,2);
         
         $dia=(integer)$dia;
         $mes=(integer)$mes;
         $mes=$nombres_mes[$mes];
         
         
         $cadena=$dia."/".$mes."/".$ano;
         return($cadena);
      }
      while($row = mysql_fetch_array($sql)) {
         $autor = $row['autor'];
         $fecha = obtener_fecha_dmY($row['fecha']);
         $email = $row['email'];
         $web = $row['web'];
         $comentario = nl2br($row['comentario']); // usamos la funcion nl2br() para los saltos de linea
?>
         <table width="650" border="1" cellpadding="1" cellspacing="1">
           <tr>
            <td>Nombre: <?=$autor?></td>
            <td colspan="2">Fecha: <?=$fecha?></td>
           </tr>
           <tr>
            <td>Email: <?=$email?></td>
            <td colspan="2">Web: <?=$web?></td>
           </tr>
           <tr>
            <td colspan="3"><?=$comentario?></td>
           </tr>
         </table><br />
<?php
         }
      if(mysql_num_rows($sql) == 15) { // consultamos si el límite de firmas permitidas ya llegó a 15
         echo "Límite de firmas permitidas terminado";
      }else { // de no haber llegado aún a 15 mostramos el formulario para seguir firmando
?>
         <table width="650" border="0" cellpadding="1" cellspacing="1">
            <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
               <tr>
                  <td>Nombre:</td>
                  <td>
                     <input type="text" name="autor" maxlength="30" />
                  </td>
               </tr>
               <tr>
                  <td>Email:</td>
                  <td>
                     <input type="text" name="email" maxlength="40" />
                  </td>
               </tr>
               <tr>
                  <td>P&aacute;gina web: </td>
                  <td>
                     <input type="text" name="web" maxlength="40" />
                  </td>
               </tr>
               <tr>
                  <td colspan="2">Mensaje:</td>
               </tr>
               <tr>
                  <td colspan="2">
                     <textarea name="comentario" rows="8" style="width: 90%;"></textarea>
                  </td>
               </tr>
               <tr>
                  <td colspan="2">
                     <input type="submit" name="firma" value="Enviar datos" /> 
                     <input type="reset" value="Restablecer" />
                  </td>
               </tr>
            </form>
         </table>
<?php
      }
   }
?>


Espero que te sirva.

Saludos.

Por MijT

97 de clabLevel

1 tutorial

 

Lima - Perú

firefox
Citar            
MensajeEscrito el 09 May 2007 07:13 pm
Espectacular...exelente....lo pruebo y cualquier cosa te aviso...demas esta decirte que te agradezco muchisimo que realmente siento haberte molestado..muchas gracias, estamos en contacto! una abrazo!

Por ramon_123

14 de clabLevel



 

msie
Citar            
MensajeEscrito el 09 May 2007 07:15 pm
De nada, estamos para ayudar, acabo de editar el post añadiendo la tabla MySQL que creé para que pueda funcionar el script.

Saludos.

Por MijT

97 de clabLevel

1 tutorial

 

Lima - Perú

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.