Foros del Web » Programando para Internet » PHP »

Mensaje con echo

Estas en el tema de Mensaje con echo en el foro de PHP en Foros del Web. Hola amigos, que tal, les comento estoy haciendo un codigo que es el action de un formulario en donde el usuario introduce un par de ...
  #1 (permalink)  
Antiguo 08/05/2010, 10:02
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Mensaje con echo

Hola amigos, que tal, les comento estoy haciendo un codigo que es el action de un formulario en donde el usuario introduce un par de cosas; y si introduce caracteres invalidos como &, <> se enumera el error.
La cuestion es la siguiente, al introducir esos caracteres salta el mensaje de error, pero si no se introducen, no puedo lograr que salte el mensaje de Datos guardados con exito.
Dejo el codigo para que vean que es lo que estoy haciendo mal:

update.php:

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es-es">
  3. <head>
  4. <?php
  5. error_reporting(E_ALL ^ E_NOTICE);
  6. session_name('pLogin');
  7. include('connect.php'); //incluimos el config.php que contiene los datos de la conexi&oacute;n a la db
  8. $usuario=$_SESSION['usuario'];
  9.  
  10.  
  11. $errcnt=0;
  12. if(count($_POST)<>0)        //IF SOME FORM WAS POSTED DO VALIDATION
  13. {
  14.         {
  15.             $firstname=str_replace("$","\$",addslashes($_REQUEST["firstname"]));
  16.             $lastname=str_replace("$","\$",addslashes($_REQUEST["lastname"]));
  17.             $ocupacion=str_replace("$","\$",addslashes($_REQUEST["ocupacion"]));
  18.  
  19.  
  20. }
  21.         else
  22.         {
  23.            
  24.             $firstname=str_replace("$","\$",addslashes($_REQUEST["firstname"]));
  25.             $lastname=str_replace("$","\$",addslashes($_REQUEST["lastname"]));
  26.             $ocupacion=str_replace("$","\$",addslashes($_REQUEST["ocupacion"]));
  27.  
  28.  
  29. }
  30. if ( strlen(trim($firstname)) == 0 )
  31.     {
  32.         $errs[$errcnt]="Firstname must be provided";
  33.         $errcnt++;
  34.     }
  35.     elseif(preg_match ("/[;<>&]/", $_REQUEST["firstname"]))
  36.     {
  37.         $errs[$errcnt]="Firstname can not have any special character (e.g. & ; < >)";
  38.         $errcnt++;
  39.     }
  40.  
  41.     if ( strlen(trim($lastname)) == 0 )
  42.     {
  43.         $errs[$errcnt]="Lastname must be provided";
  44.         $errcnt++;
  45.     }
  46.     elseif(preg_match ("/[;<>&]/", $_REQUEST["lastname"]))
  47.     {
  48.         $errs[$errcnt]="Lastname can not have any special character (e.g. & ; < >)";
  49.         $errcnt++;
  50.     }
  51.  
  52.     if ( strlen(trim($ocupacion)) == 0 )
  53.     {
  54.         $errs[$errcnt]="Ocupacion debe ser completada";
  55.         $errcnt++;
  56.     }
  57.     elseif(preg_match ("/[;<>&]/", $_REQUEST["ocupacion"]))
  58.     {
  59.         $errs[$errcnt]="Ocupacion no debe tener caracteres especiales (e.g. & ; < >)";
  60.         $errcnt++;
  61.     }
  62.    
  63.  
  64.  
  65. if($errcnt==0)
  66. {
  67.     mysql_query("
  68. UPDATE members
  69. SET firstname='".trim($firstname)."',lastname='".trim($lastname)."',ocupacion='$ocupacion'
  70. WHERE usuario='$_SESSION[usuario]'  ");
  71. }
  72. if  (count($_POST)>0)
  73. {
  74. $firstname=$_REQUEST["firstname"];
  75. $lastname=$_REQUEST["lastname"];
  76. $ocupacion=$_REQUEST["ocupacion"];
  77.  
  78. if ( $errcnt<>0 )
  79. {
  80. ?>
  81.  
  82.  
  83.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  84.    
  85.  
  86.     <title>prueba</title>
  87.  
  88.  
  89. </head>
  90.  
  91. <body>
  92.  
  93. <div id="prueba">
  94.   <tr>
  95.     <td colspan="2"><strong>No se pudo ejecutar el update debido a las siguientes razones</strong></td>
  96.   </tr>
  97.   <tr height="10">
  98.     <td colspan="2"></td>
  99.   </tr>
  100.   <?php
  101.  
  102. for ($i=0;$i<$errcnt;$i++)
  103. {
  104. ?>
  105.   <tr valign="top">
  106.     <td width="6%">&nbsp;<?php echo $i+1;?></td>
  107.     <td width="94%"><?php echo  $errs[$i]; ?></td>
  108.   </tr>
  109.   <?php
  110. }
  111. ?>
  112. </table>
  113. <?php
  114.  
  115. }
  116.  
  117. }
  118.  
  119.  else {
  120.  
  121.     echo '<span class="Estilo24">Datos Guardados con &eacute;xito</span>';
  122.  
  123.     }
  124.  
  125. }
  126. ?>
  127. </div>
  128. </body>
  129. </html>

Gracias
  #2 (permalink)  
Antiguo 08/05/2010, 12:20
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Mensaje con echo

Cambie un par de cosas, el mensaje de error lo muestra, pero si no hay ningun caracter especial, y está todo bien, la pagina con la div cont_succes no se muestra y no aparece el datos guardados con exito.

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es-es">
  3. <head>
  4. <?php
  5. error_reporting(E_ALL ^ E_NOTICE);
  6. session_name('pLogin');
  7. include('connect.php'); //incluimos el config.php que contiene los datos de la conexi&oacute;n a la db
  8. $usuario=$_SESSION['usuario'];
  9.  
  10.  
  11. $errcnt=0;
  12. if(count($_POST)<>0)        //IF SOME FORM WAS POSTED DO VALIDATION
  13. {
  14.         {
  15.             $firstname=str_replace("$","\$",addslashes($_REQUEST["firstname"]));
  16.             $lastname=str_replace("$","\$",addslashes($_REQUEST["lastname"]));
  17.             $ocupacion=str_replace("$","\$",addslashes($_REQUEST["ocupacion"]));
  18.  
  19.  
  20. }
  21.         else
  22.         {
  23.            
  24.             $firstname=str_replace("$","\$",addslashes($_REQUEST["firstname"]));
  25.             $lastname=str_replace("$","\$",addslashes($_REQUEST["lastname"]));
  26.             $ocupacion=str_replace("$","\$",addslashes($_REQUEST["ocupacion"]));
  27.  
  28.  
  29. }
  30. if ( strlen(trim($firstname)) == 0 )
  31.     {
  32.         $errs[$errcnt]="Firstname must be provided";
  33.         $errcnt++;
  34.     }
  35.     elseif(preg_match ("/[;<>&]/", $_REQUEST["firstname"]))
  36.     {
  37.         $errs[$errcnt]="Firstname can not have any special character (e.g. & ; < >)";
  38.         $errcnt++;
  39.     }
  40.  
  41.     if ( strlen(trim($lastname)) == 0 )
  42.     {
  43.         $errs[$errcnt]="Lastname must be provided";
  44.         $errcnt++;
  45.     }
  46.     elseif(preg_match ("/[;<>&]/", $_REQUEST["lastname"]))
  47.     {
  48.         $errs[$errcnt]="Lastname can not have any special character (e.g. & ; < >)";
  49.         $errcnt++;
  50.     }
  51.  
  52.     if ( strlen(trim($ocupacion)) == 0 )
  53.     {
  54.         $errs[$errcnt]="Ocupacion debe ser completada";
  55.         $errcnt++;
  56.     }
  57.     elseif(preg_match ("/[;<>&]/", $_REQUEST["ocupacion"]))
  58.     {
  59.         $errs[$errcnt]="Ocupacion no debe tener caracteres especiales (e.g. & ; < >)";
  60.         $errcnt++;
  61.     }
  62.    
  63.  
  64.  
  65. if($errcnt==0)
  66. {
  67.     mysql_query("
  68. UPDATE members
  69. SET firstname='".trim($firstname)."',lastname='".trim($lastname)."',ocupacion='$ocupacion'
  70. WHERE usuario='$_SESSION[usuario]'  ");
  71. }
  72. if  (count($_POST)>0)
  73. {
  74. $firstname=$_REQUEST["firstname"];
  75. $lastname=$_REQUEST["lastname"];
  76. $ocupacion=$_REQUEST["ocupacion"];
  77.  
  78. if ( $errcnt<>0 )
  79. {
  80. ?>
  81.  
  82.  
  83.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  84.    
  85.  
  86.     <title>prueba</title>
  87.  
  88.  
  89. </head>
  90.  
  91. <body>
  92.  
  93. <div id="prueba">
  94.   <tr>
  95.     <td colspan="2"><strong>No se pudo ejecutar el update debido a las siguientes razones</strong></td>
  96.   </tr>
  97.   <tr height="10">
  98.     <td colspan="2"></td>
  99.   </tr>
  100.   <?php
  101.  
  102. for ($i=0;$i<$errcnt;$i++)
  103. {
  104. ?>
  105.   <tr valign="top">
  106.     <td width="6%">&nbsp;<?php echo $i+1;?></td>
  107.     <td width="94%"><?php echo  $errs[$i]; ?></td>
  108.   </tr>
  109.   </div>
  110.  <?php
  111. }
  112. ?>
  113. <div id="cont_success">
  114. <?php
  115. }
  116. }
  117.  
  118. else{
  119. ?>
  120. <td width="94%"><?php echo '<span class="Estilo24">Datos Guardados con éxito</span>'; ?></td>
  121. </table>
  122. <?php
  123. }
  124. }
  125. ?>
  126. </div>

Etiquetas: echo, mensaje
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:16.