Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2013, 08:48
etobcn
 
Fecha de Ingreso: enero-2011
Mensajes: 16
Antigüedad: 13 años, 3 meses
Puntos: 0
Pregunta No redirecciona a otra pagina desde un include

Buenas a todos compis

Soy nuevo en el foro y querria haceros una consulta que me está volviendo loco.
Seguro es una chorrada pero no se xq pasa.

He creado un simple form de inserccion de un registro y lo he incluido mediante un include en otra página (se que en este ejemplo es absurdo, pero es para que lo veais fácil, y en mi proyecto me interesa para no ensuciar la index y incluir los forms de registro y identificación).

Todas las páginas estan en la misma raiz. Y si intento insertar un registro, me lo inserta correctamente en la BD pero no me redirige a la página (en este caso index).

En cambio si lo hago desde la pagina original, funciona perfectamente.

Es como si la funcion de*$insertGoTo = "index.php", no funcionara desde un include.
El código está creado con Dreamweaver, ya que no soy un lumbreras que digamos con php.

Adjunto los codigos de las dos páginas

Pagina del formulario:
Código PHP:
Ver original
  1. <?php
  2. if (!function_exists("GetSQLValueString")) {
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5.   if (PHP_VERSION < 6) {
  6.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.   }
  8.  
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  11.   switch ($theType) {
  12.     case "text":
  13.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14.       break;    
  15.     case "long":
  16.     case "int":
  17.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18.       break;
  19.     case "double":
  20.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  21.       break;
  22.     case "date":
  23.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24.       break;
  25.     case "defined":
  26.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27.       break;
  28.   }
  29.   return $theValue;
  30. }
  31. }
  32.  
  33. $editFormAction = $_SERVER['PHP_SELF'];
  34. if (isset($_SERVER['QUERY_STRING'])) {
  35.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  36. }
  37.  
  38. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  39.   $insertSQL = sprintf("INSERT INTO tblusers (nombre, email, password) VALUES (%s, %s, %s)",
  40.                        GetSQLValueString($_POST['nombre'], "text"),
  41.                        GetSQLValueString($_POST['email'], "text"),
  42.                        GetSQLValueString($_POST['password'], "text"));
  43.  
  44.   mysql_select_db($database_conexionwhatoo, $conexionwhatoo);
  45.   $Result1 = mysql_query($insertSQL, $conexionwhatoo) or die(mysql_error());
  46.  
  47.   $insertGoTo = "index.php";
  48.   if (isset($_SERVER['QUERY_STRING'])) {
  49.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  50.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  51.   }
  52.   header(sprintf("Location: %s", $insertGoTo));
  53. }
  54. ?>
  55.  
  56. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  57.   <table align="center">
  58.     <tr valign="baseline">
  59.       <td nowrap="nowrap" align="right">Nombre:</td>
  60.       <td><input type="text" name="nombre" value="" size="32" /></td>
  61.     </tr>
  62.     <tr valign="baseline">
  63.       <td nowrap="nowrap" align="right">Email:</td>
  64.       <td><input type="text" name="email" value="" size="32" /></td>
  65.     </tr>
  66.     <tr valign="baseline">
  67.       <td nowrap="nowrap" align="right">Password:</td>
  68.       <td><input type="text" name="password" value="" size="32" /></td>
  69.     </tr>
  70.     <tr valign="baseline">
  71.       <td nowrap="nowrap" align="right">&nbsp;</td>
  72.       <td><input type="submit" value="Insertar registro" /></td>
  73.     </tr>
  74.   </table>
  75.   <input type="hidden" name="MM_insert" value="form1" />
  76. </form>
  77. <p>&nbsp;</p>

Y esta es la página con el include
Código PHP:
Ver original
  1. <?php require_once('Connections/conexionwhatoo.php'); ?>
  2. <!DOCTYPE html>
  3. <html lang="es">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <title>prueba</title>
  7. </head>
  8.  
  9. <body>
  10. <div><?php include("prueba_form.php"); ?></div>
  11. </body>
  12. </html>

Muchas gracias y espero me deis con la solucion yaque me estoy volviendo loco