Foros del Web » Programando para Internet » PHP »

Duda sobre $_SERVER['PHP_SELF']

Estas en el tema de Duda sobre $_SERVER['PHP_SELF'] en el foro de PHP en Foros del Web. Hola a todos tengo un problemilla en mi host local tengo un formulario que guarda todo normal sin problemas. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original ...
  #1 (permalink)  
Antiguo 18/08/2011, 08:55
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Duda sobre $_SERVER['PHP_SELF']

Hola a todos tengo un problemilla en mi host local tengo un formulario que guarda todo normal sin problemas.

Código HTML:
Ver original
  1. <form action="$_SERVER['PHP_SELF'] " method="post" enctype="multipart/form-data">  
  2. <h1 align="center" class="titulo">NUEVA NOTA DE PRENSA</h1>
  3. <table  align="center" id="datos" >
  4. <tr>
  5.     <th></th>
  6.     <td><input name="id" type="hidden" size="430"> </td>
  7.   </tr>
  8.   <tr>
  9.     <th>Imagen</th>
  10.     <td><input name="fichero" type="file" size="30" maxlength="150"></td>
  11.   </tr>

Pero cuando lo subo al servidor no me guarda, solo la imagen en la carpeta que elegi pero no los datos .

Creen que el problema sea el action $_SERVER['PHP_SELF'], ya he trabajado antes asi y funcionaba. Debo usar mejor el nombre del formulario en vez del $_SERVER['PHP_SELF']? Cual es el mas recomendable, ya que el modificar que es casi lo mismo que el guardar me funciona normal.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #2 (permalink)  
Antiguo 18/08/2011, 08:59
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Duda sobre $_SERVER['PHP_SELF']

No creo que sea problema de $_SERVER['PHP_SELF'], si dices que guarda la imagen pero no los datos el problema no está en el formulario.

¿Pero como adivinar que estas haciendo con el código que recibe el formulario?

PDTA: para enviar el formulario hacía si mismo no hace falta $_SERVER['PHP_SELF'], con que dejes el action vacío basta.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 18/08/2011, 09:04
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

XD tienes razon aqui pongo el codigo el principio que es java es del calendario que tengo.

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>NOTAS DE PRENSA</title>
  5. <link rel="stylesheet" type="text/css" media="all" href="../jscalendar/skins/aqua/theme.css" title="Aqua" />
  6. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-blue.css" title="winter" />
  7. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-blue2.css" title="blue" />
  8. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-brown.css" title="summer" />
  9. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-green.css" title="green" />
  10. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-win2k-1.css" title="win2k-1" />
  11. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-win2k-2.css" title="win2k-2" />
  12. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-win2k-cold-1.css" title="win2k-cold-1" />
  13. <link rel="alternate stylesheet" type="text/css" media="all" href="../jscalendar/calendar-win2k-cold-2.css" title="win2k-cold-2" />
  14. <link rel="stylesheet" type="text/css" href="../css/admin.css"/>
  15. <link rel="alternate stylesheet" type="text/css" media="all" href="calendar-system.css" title="system" />
  16. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  17. <script type="text/javascript" src="../jscalendar/calendar.js"></script>
  18. <script type="text/javascript" src="../jscalendar/lang/calendar-es.js"></script>
  19. <script src="../css/jquery.js" type="text/javascript"></script>
  20. <script src="prueba.js" type="text/javascript"></script>
  21. <script type="text/javascript">
  22.  
  23. var oldLink = null;
  24.  
  25. function setActiveStyleSheet(link, title) {
  26.   var i, a, main;
  27.   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  28.     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
  29.       a.disabled = true;
  30.       if(a.getAttribute("title") == title) a.disabled = false;
  31.     }
  32.   }
  33.   if (oldLink) oldLink.style.fontWeight = 'normal';
  34.   oldLink = link;
  35.   link.style.fontWeight = 'bold';
  36.   return false;
  37. }
  38.  
  39. function selected(cal, date) {
  40.   cal.sel.value = date;
  41.   if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
  42.     cal.callCloseHandler();
  43. }
  44. function closeHandler(cal) {
  45.   cal.hide();                        
  46.   _dynarch_popupCalendar = null;
  47. }
  48. function showCalendar(id, format, showsTime, showsOtherMonths) {
  49.   var el = document.getElementById(id);
  50.   if (_dynarch_popupCalendar != null) {
  51.    
  52.     _dynarch_popupCalendar.hide();                
  53.   } else {
  54.     var cal = new Calendar(1, null, selected, closeHandler);
  55.     if (typeof showsTime == "string") {
  56.       cal.showsTime = true;
  57.       cal.time24 = (showsTime == "24");
  58.     }
  59.     if (showsOtherMonths) {
  60.       cal.showsOtherMonths = true;
  61.     }
  62.     _dynarch_popupCalendar = cal;                
  63.     cal.setRange(1900, 2070);      
  64.     cal.create();
  65.   }
  66.   _dynarch_popupCalendar.setDateFormat(format);    
  67.   _dynarch_popupCalendar.parseDate(el.value);      
  68.   _dynarch_popupCalendar.sel = el;                
  69.  
  70.   _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");      
  71.  
  72.   return false;
  73. }
  74.  
  75. var MINUTE = 60 * 1000;
  76. var HOUR = 60 * MINUTE;
  77. var DAY = 24 * HOUR;
  78. var WEEK = 7 * DAY;
  79.  
  80. function isDisabled(date) {
  81.   var today = new Date();
  82.   return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
  83. }
  84.  
  85. function flatSelected(cal, date) {
  86.   var el = document.getElementById("preview");
  87.   el.innerHTML = date;
  88. }
  89.  
  90. function showFlatCalendar() {
  91.   var parent = document.getElementById("display");
  92.   var cal = new Calendar(0, null, flatSelected);
  93.  
  94.   cal.weekNumbers = false;
  95.   cal.setDisabledHandler(isDisabled);
  96.   cal.setDateFormat("%A, %B %e");
  97.   cal.create(parent);
  98.   cal.show();
  99. }
  100. </script>
  101.  
  102.  
  103. </head>
  104. <?php  
  105. if (isset($_POST['submit'])) {  
  106.     if(is_uploaded_file($_FILES['fichero']['tmp_name'])) {
  107.    
  108.         $ruta_destino = ".../.../fotos/";
  109.         $ruta_destino2 = "http://localhost/fotos/";
  110.         $namefinal= trim ($_FILES['fichero']['name']);
  111.      
  112.         $uploadfile= $ruta_destino . $namefinal;  
  113.         $uploadfile2= $ruta_destino2 . $namefinal;  
  114.  
  115.         if(move_uploaded_file($_FILES['fichero']['tmp_name'], $uploadfile)) { // se coloca en su lugar final  
  116.                    
  117.                    
  118. //conectamos a la base de datos para almacenar los datos y la ruta del archivo
  119.  
  120. $server="localhost";
  121. $usuario="root";
  122. $pass="";
  123. $bd="bd";
  124. $link=mysql_connect($server,$usuario,$pass)or die (exit(mysql_error()));
  125.                  $id  = $_POST["id"];
  126.                    $fecha  = $_POST["fecha"];
  127.                    $titulo  = $_POST["titulo"];
  128.                    $descripcion  = $_POST["descripcion"];
  129.                   $query = "INSERT INTO notas_prensa  
  130.   VALUES ('$id','$fecha','$titulo','$descripcion', '".$uploadfile2."','".$uploadfile."')";
  131.    echo "<script languaje='javascript'>alert('Datos Guardados.')
  132.             document.location = ('../presentacion/frmnotas_prensag.php');
  133.             </script>";
  134.        
  135.  
  136.                    
  137.                    
  138.        mysql_query($query) or die(mysql_error());
  139.        
  140.         }  
  141.     }  
  142.  }
  143. //Formulario  
  144.  
  145. ?>
  146. <body onload="showFlatCalendar()" bgcolor="#F9F9F9">
  147. <script type="text/javascript">
  148. setActiveStyleSheet(document.getElementById("defaultTheme"), "Aqua");
  149. </script>
  150. </div>
  151.  
  152. <form action="frmnotas_prensag.php" method="post" enctype="multipart/form-data">  
  153. <h1 align="center" class="titulo">NUEVA NOTA DE PRENSA</h1>
  154. <table  align="center" id="datos" >
  155. <tr>
  156.     <th></th>
  157.     <td><input name="id" type="hidden" size="430"> </td>
  158.   </tr>
  159.   <tr>
  160.     <th>Imagen</th>
  161.     <td><input name="fichero" type="file" size="30" maxlength="150"></td>
  162.   </tr>
  163.   <tr>
  164.     <th>Fecha</th>
  165.     <td> <input type="text" name="fecha" id="sel4" size="30"  ><input type="reset" value=" ... "
  166. onclick="return showCalendar('sel4','%Y-%m-%d');"><div id="display" style="display:none"></div>  </tr>
  167.   <tr>
  168.     <th>Titulo</th>
  169.    
  170.     <td><input type="text" id="titulo"  size="30" name="titulo"/>
  171.       <input type="button" id="chequeo" value="Verificar"/>
  172.       <br/>
  173.       <div id="resultado"></div></td>
  174. </td>
  175.   </tr>
  176.   <tr>
  177.     <th>Descripcion</th>
  178.     <td ><textarea name="descripcion" cols="40" rows="10"></textarea> </td>
  179.   </tr>
  180.   <tr>
  181.     <td colspan="2" align="center"><input name="submit" type="submit" value="Guardar" id="button"></td>
  182.     </tr>
  183. </table>
  184.  
  185. </form>
  186. <div id="display" style="display:none"></div>
  187.             <p style="display:none"><small>
  188. </body>
  189. </html>
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #4 (permalink)  
Antiguo 18/08/2011, 09:10
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

para mi tenes muy mal esto:
<form action="$_SERVER['PHP_SELF'] " method="post" enctype="multipart/form-data">
cambialo por:
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
  #5 (permalink)  
Antiguo 18/08/2011, 09:12
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Cita:
Iniciado por pateketrueke Ver Mensaje

PDTA: para enviar el formulario hacía si mismo no hace falta $_SERVER['PHP_SELF'], con que dejes el action vacío basta.
si lo dejas vacio no va a ser interpretado de la misma forma en todos los navegadores
  #6 (permalink)  
Antiguo 18/08/2011, 09:19
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Cita:
Iniciado por Patriarka Ver Mensaje
si lo dejas vacio no va a ser interpretado de la misma forma en todos los navegadores
De hecho si, te lo digo por experiencia.

CesarHC, parece que si estás recibiendo bien las variables.

Intenta imprimir la consulta antes de ejecutarla y muestranos.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #7 (permalink)  
Antiguo 18/08/2011, 09:24
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

He probado dejandalo en blanco y responde sin problemas con ie y moz en local, no puedo probarlo ahora en el server ya que en este momento no tengo acceso.

He encontrado esto en el manual de PHP y tal vez el problema si sea si sea $_SERVER['PHP_SELF']:

$_SERVER es un array que contiene información, tales como cabeceras, rutas y localizaciones del código. Las entradas en este array son creadas por el servidor web. No existe garantía que cada servidor web proporcione todas estas entradas, ya que existen servidores que pueden omitir algunas o proporcionar otras que no se encuentran recogidas aquí. Un gran número de estas variables se encuentran recogidas en » especificación CGI 1.1, así que al menos debe esperar encontrar estas entradas.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.

Última edición por CesarHC; 18/08/2011 a las 09:41
  #8 (permalink)  
Antiguo 18/08/2011, 09:57
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

solucion definitiva: le pones el archivo.php que corresponde a cada action y se termino!
  #9 (permalink)  
Antiguo 18/08/2011, 10:00
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Yo estoy seguro que el problema no es de PHP_SELF, de verdad, he hecho tantos scripts en mi vida usando dicha variable y/o el action vacío y los resultados son los mismos.

Quizá el problema está en otro lugar.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #10 (permalink)  
Antiguo 18/08/2011, 10:02
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 11 meses
Puntos: 394
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Cita:
Iniciado por Patriarka Ver Mensaje
solucion definitiva: le pones el archivo.php que corresponde a cada action y se termino!
Exacto.... te recomiendo que leas un poco acerca del patrón MVC que a mi me ha sacado de unos problemas que ni te imaginas...
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #11 (permalink)  
Antiguo 18/08/2011, 10:04
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Te sube el fichero, pero no te inserta datos en la base de datos???

Si es asi, revisa la cadena de la sentencia sql, visto por encima, creo que no esta bien concatenada y por eso puede ser que falle y no te inserte los datos.

Otra cosa, por que no pones mejor el mysql_query ANTES del echo del javascript location????? por probar...
  #12 (permalink)  
Antiguo 18/08/2011, 10:35
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

bueno pasemos al siguiente problema:
en el arcvhivo que procesa hace

echo '<pre>';
print_r($_FILES);
echo '</pre>';

y vemos que te llega de FILES

y ya que esta mostranos como intentas guardar la imagen
  #13 (permalink)  
Antiguo 18/08/2011, 10:53
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Si ya puse la ruta del formulario, que es el nombre del formulario con eso deberia bastar ya lo probare en la noche ahora mismo no tengo acceso al servidor.Gracias a todos por su ayuda.Ya les aviso como me fue.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #14 (permalink)  
Antiguo 19/08/2011, 06:53
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Solo para terminar el tema remplaze el $_SERVER['PHP_SELF'] por el nombre del formulario y ya anda normal.Tema cerrado.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #15 (permalink)  
Antiguo 19/08/2011, 08:40
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

como por el nombre del form?
asi: <form name="form_feo" action="form_feo" ....>
  #16 (permalink)  
Antiguo 19/08/2011, 08:51
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Creo que no me exprese bien quise decir que el nombre del archivo php es digamos
"nota.php" ese nombre es lo que puse en el action en vez de $_SERVER['PHP_SELF'].

osea que queda:

<form action="notas.php" method="post" enctype="multipart/form-data">
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #17 (permalink)  
Antiguo 19/08/2011, 09:23
Avatar de Patriarka  
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 2 meses
Puntos: 288
Respuesta: Duda sobre $_SERVER['PHP_SELF']

ahora si, mejor aclarado pense que hiciste una locura
  #18 (permalink)  
Antiguo 19/08/2011, 09:27
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: Duda sobre $_SERVER['PHP_SELF']

Jajaja locura me hiciste reir XD
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.

Etiquetas: formulario
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 19:27.