Ver Mensaje Individual
  #11 (permalink)  
Antiguo 05/05/2012, 18:39
Avatar de chwc
chwc
 
Fecha de Ingreso: julio-2008
Ubicación: Buenos Aires ! :D
Mensajes: 814
Antigüedad: 16 años, 7 meses
Puntos: 103
Respuesta: Error en strlen

haz una cosa, primero que nada no inicializes las variables como dijieron anteriormente, y luego cambia esto :
Código PHP:
Ver original
  1. if($error['titulo']=="si"){
por esto:
Código PHP:
Ver original
  1. if(isset($error['titulo'])){
y ademas esto
Código PHP:
Ver original
  1. if($error['nota']=="si"){
por esto
Código PHP:
Ver original
  1. if(isset($error['nota'])){

quedandote asi:
Código PHP:
Ver original
  1. <?php
  2. $error=array();
  3. //validacion
  4. if(strlen($_POST['titulo'])==0){ //strlen te dice cuanto mide una variable
  5.     $error['titulo']="si";
  6. }else{
  7.     $titulo=$_POST['titulo'];
  8. }
  9. if(strlen($_POST['nota'])==0){
  10.     $error['nota']="si";
  11. }else{
  12.     $nota=$_POST['nota'];
  13. }
  14. //cierre validacion
  15.  
  16. if(count($error)>0){
  17.     if(isset($error['titulo'])){
  18.         echo "<h3> Error en el titulo </h3>";
  19.     }
  20.         if(isset($error['nota'])){
  21.             echo "<h3> Error en la nota </h3>";
  22.         }
  23.         echo "<h3> ERROR: ¡NO SE GUARDO! </h3>";
  24.     }else{
  25.        
  26.     if(file_exists("mensajes.txt")){
  27.         $db=unserialize(file_get_contents("mensajes.txt"));
  28.     }else{
  29.         $db=array();
  30.     }}
  31.     $fila=array();
  32.     $fila['titulo']=$titulo;
  33.     $fila['nota']=$nota;
  34.     $db[]=$fila;
  35.     file_put_contents("mensajes.txt",serialize($db));
  36.     echo "<h1>GUARDADO</h1>";
  37.    
  38.  
  39. ?>

saludos y suerte :D