Foros del Web » Programando para Internet » PHP »

problema en toma de decisión

Estas en el tema de problema en toma de decisión en el foro de PHP en Foros del Web. Saludos tengo en problema con este código necesito que en caso de que en la consulta no encuentre el dato los mande a otra agina ...
  #1 (permalink)  
Antiguo 25/02/2013, 11:43
 
Fecha de Ingreso: febrero-2013
Mensajes: 66
Antigüedad: 11 años, 2 meses
Puntos: 1
Información problema en toma de decisión

Saludos tengo en problema con este código necesito que en caso de que en la consulta no encuentre el dato los mande a otra agina lo he intentado colocando un header('Location: datos.php'); pero al parecer ignora esa instrucción gracias
Código PHP:
Ver original
  1. <title> datos</title>
  2. <form method="post" action="actualia.php">
  3. <table width="200" border="0" align="center" cellspacing="0">
  4.   <tr>
  5.     <td height="148"><img src="log[1].jpg" width="150" height="133" /></td>
  6.     <td><img src="CABESERA.png" width="801" height="144" /></td>
  7.   </tr>
  8. </table>
  9. <?php
  10. //Conexi贸n con el servidor
  11. $con=mysql_connect("localhost","root","");
  12.    if (!$con){die('ERROR DE CONEXION CON MYSQL:'. mysql_error());}
  13. /********* CONECTA CON LA BASE DE DATOS  **************** */
  14. $database = mysql_select_db("aaaaa",$con);
  15. if (!$database){die('ERROR CONEXION CON BD:'.mysql_error());}  
  16. /* ****************************************************** */
  17. //ejecutamos la consulta
  18.             $SQL="Select*From DATOSFISCALES WHERE RFC='".$_POST['rfc']."'";
  19. $result = mysql_query ($SQL);
  20. // verificamos que no haya error
  21. if (! $result){
  22.    header('Location:  datos.php');
  23. exit();
  24. }else {
  25.     echo "<table width='600' border='0' align='center'>
  26. <tr><td><h3><font color='red'>SI SUS DATOS SON INCORRECTOS MODIFIQUE AHORA </td></h3></tr></font>
  27.  </table>
  28.     </tr>";
  29. echo "<table width='150' border='0' align='left'>
  30. <tr>
  31. </td>
  32. <tr>
  33.     <tr><td>RFC</td>  </tr>
  34.     <tr><td>NOMBRE</td>  </tr>
  35.     <tr><td>CALLE</td>  </tr>
  36.     <tr><td>NO EXTERIOR</td>  </tr>
  37.     <tr><td>NO INTERIOR</td>  </tr>  
  38.     <tr><td>CODIGO POSTAL</td>  </tr>
  39.     <tr><td>COLONIA</td>  </tr>
  40.     <tr><td>POBLACION</td>  </tr>
  41.     <tr><td>PAIS</td>  </tr>
  42.     <tr><td>E-mail</td>  </tr>
  43.    </table>
  44.     </tr>";
  45. //obtenemos los datos resultado de la consulta
  46.  
  47.     while ($row = mysql_fetch_row($result))
  48.     {
  49. echo "<input type=text name=RFC      size=50 value=".$row[1]."><br>";
  50. echo "<textarea rows=1 cols=39 name=nombre >".$row[2]."</textarea><br>";
  51. echo "<input type=text name=calle    size=50 value=".$row[3]."><br>";
  52. echo "<input type=text name=exterior size=50 value=".$row[4]."><br>";
  53. echo "<input type=text name=interior size=50 value=".$row[5]."><br>";
  54. echo "<input type=text name=codigo   size=50 value=".$row[6]."><br>";
  55. echo "<input type=text name=colonia  size=50 value=".$row[7]."><br>";  
  56. echo "<input type=text name=estado   size=50 value=".$row[8]."><br>";
  57. echo "<input type=text name=pais     size=50 value=".$row[10]."><br>";
  58. echo "<input type=text name=email    size=50 value=".$row[11]."><br>";
  59.     }
  60.     }
  61. ?>
  62. <p><input type="submit" name="guardar" value=" Guardar "><br>
  63. </p>
  64. </form>
  #2 (permalink)  
Antiguo 25/02/2013, 12:14
Avatar de stramin  
Fecha de Ingreso: marzo-2008
Ubicación: Cubil felino
Mensajes: 1.652
Antigüedad: 16 años, 1 mes
Puntos: 336
Respuesta: problema en toma de decisión

No se puede cambiar el cabezal si ya lo has definido previamente, tienes 2 opciones:

1.- Mover el html más abajo asi:

Código PHP:
Ver original
  1. <?php
  2. //Conexi贸n con el servidor
  3. $con=mysql_connect("localhost","root","");
  4.    if (!$con){die('ERROR DE CONEXION CON MYSQL:'. mysql_error());}
  5. /********* CONECTA CON LA BASE DE DATOS  **************** */
  6. $database = mysql_select_db("aaaaa",$con);
  7. if (!$database){die('ERROR CONEXION CON BD:'.mysql_error());}  
  8. /* ****************************************************** */
  9. //ejecutamos la consulta
  10.             $SQL="Select*From DATOSFISCALES WHERE RFC='".$_POST['rfc']."'";
  11. $result = mysql_query ($SQL);
  12. // verificamos que no haya error
  13. if (! $result){
  14.    header('Location:  datos.php');
  15. exit();
  16. }else { ?>
  17. <title> datos</title>
  18. <form method="post" action="actualia.php">
  19. <table width="200" border="0" align="center" cellspacing="0">
  20.   <tr>
  21.     <td height="148"><img src="log[1].jpg" width="150" height="133" /></td>
  22.     <td><img src="CABESERA.png" width="801" height="144" /></td>
  23.   </tr>
  24. </table> <?php echo "<table width='600' border='0' align='center'>
  25. <tr><td><h3><font color='red'>SI SUS DATOS SON...

2.- Hacerlo con javascript así:

Código PHP:
Ver original
  1. if (! $result){
  2.    echo "<script>document.location.href='datos.php';</script>";
  3. exit();
  4. }else {

Espero te sirva y no haberme equivocado XD
__________________
El objetivo de este foro es orientar al usuario como un favor y no como una obligación.

Yo soy de los que dan puntos por aporte :D
  #3 (permalink)  
Antiguo 25/02/2013, 12:50
 
Fecha de Ingreso: enero-2012
Ubicación: Mexico Df
Mensajes: 95
Antigüedad: 12 años, 3 meses
Puntos: 6
Respuesta: problema en toma de decisión

y una muy buena practica es separar el código php del html así evitas que php también procese código HTML

Código PHP:
Ver original
  1. if (! $result){
  2.    ?>
  3. <script>document.location.href='datos.php';</script>"
  4. <?php
  5. exit();
  6. }else {
__________________
Mi proyecto web Desarrollo-Tech visitame http://www.desarrollo-tech.com
  #4 (permalink)  
Antiguo 25/02/2013, 12:57
 
Fecha de Ingreso: febrero-2013
Mensajes: 66
Antigüedad: 11 años, 2 meses
Puntos: 1
Respuesta: problema en toma de decisión

ola cesar_viridi he intentado de las dos formas que me has sugerido pero tengo el mismo error no ce que podria cer de antemano gracias por tu apollo

Etiquetas: mysql, select, sql, toma
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 07:45.