Foros del Web » Programando para Internet » PHP »

integrar 2 archivos php en 1

Estas en el tema de integrar 2 archivos php en 1 en el foro de PHP en Foros del Web. Hola Maestros, estoy 1 tanto agobiada, dado que llevo unos dias atareada con esto y ya necesito que me ayudeis. ! miembro de este foro ...
  #1 (permalink)  
Antiguo 04/03/2009, 03:02
 
Fecha de Ingreso: mayo-2008
Mensajes: 253
Antigüedad: 16 años
Puntos: 8
integrar 2 archivos php en 1

Hola Maestros, estoy 1 tanto agobiada, dado que llevo unos dias atareada con esto y ya necesito que me ayudeis. ! miembro de este foro me aconsejo esta web para que me descargara un codigo libre de un libro de visitas. Dicho libro contiene 2 archivos que os pongo ahora:

1-. index.php

Código PHP:
<html><head><script>function disableselect(e)
{  return false  }
function reEnable()
{  return true  }
//Si es Internet Explorer 4 o superior
document.onselectstart=new Function ("return false")
//si es Netscape6
if (window.sidebar)
{  document.onmousedown=disableselect
   document.onclick=reEnable  }</script><style>body         { font-family: tahoma; font-size: 8 pt }
.vol         { color: #0000FF }
.vol:hover   { text-decoration: underline; color: #800000 }
.mas         { color: #000000 }
.mas:hover   { text-decoration: none; color: #888888 }
a            { color: #FF0000; text-decoration: none }
a:hover      { color: #000080; text-decoration: underline }
table         { font-size: 8pt }
.boton       { background-color: #00B4FF; color: #FFFFFF; font-family: 
               verdana, arial, helvetica; font-size: 8.5pt; 
               border-left: 2px Solid #00D6FF; border-right: 2px Solid #0092DD; 
               border-top: 2px Solid #00D6FF; border-bottom: 2px Solid #0092DD }
.art         { clear: none; float: none; height: 100%; width: 100%; color: #FFFFFF; 
               text-decoration: none }
.art:hover   { background-color: #0099FF; clear: none; float: none; height: 100%; align: 
               center; width: 100%; color: #000080; text-decoration: none }
.nombre { color: #000088; text-decoration: none }
.nombre:hover { text-decoration: underline }
</style><title>Ommadawn , tu oportunidad de conocer a fondo a Mike Oldfield</title></head>
<body topmargin="0" leftmargin="0"><center>
</center>
  <center>
  </center>
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td width="75%" valign="top" bgcolor="#FFE6FF">
        <center>
          <table border="0" cellpadding="0" cellspacing="0" width="60%" height="43">
            <tr>
              <td width="100%" height="43"><fieldset><legend></legend>
                <label>
        <center>
          <center><table cellpadding="0" cellspacing="0" width="90%" border="0"><tr><td width="100%">
              <div align="center">
                <form method="GET" action="insertar.php"><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#CCCCFF">
                  <tr>
                    <td width="100%">
                      <div align="center">
                        <table border="0" cellpadding="2" cellspacing="1" width="100%">
                          <tr>
                            <td width="100%" colspan="2" bgcolor="#CCCCFF">
                              <p align="center"><b><font size="2">Deja tu comentario</font></b></td>
                          </tr>
                        </center></center>
        </center>
                  </center>
                  <tr>
                    <td width="34%" bgcolor="#E6E6FF">
                      <p align="right">Tu nombre</td>
  <center>
        <center>
        <center>
          <center>
          <td width="66%" bgcolor="#E6E6FF"><input type="text" name="nombre" size="20" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></td>
          </tr>
          </center></center>
        </center>
                  </center>
                  <tr>
                    <td width="34%" bgcolor="#E6E6FF">
                      <p align="right">Tu email</td>
  <center>
        <center>
        <center>
          <center>
          <td width="66%" bgcolor="#E6E6FF"><label><input type="text" name="email" size="20" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></label></td>
          </tr>
          </center></center>
        </center>
                  </center>
                  <tr>
                    <td width="34%" bgcolor="#E6E6FF">
                      <p align="right">Comentario</td>
  <center>
        <center>
        <center>
          <center>
          <td width="66%" bgcolor="#E6E6FF"><textarea rows="2" name="comentario" cols="50" style="font-family: 'Trebuchet MS', arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></textarea></td>
          </tr>
          </center></center>
        </center>
                  </center>
                  <tr>
                    <td width="34%" bgcolor="#E6E6FF">
                      <p align="right">Opinión sobre la web</td>
  <center>
        <center>
        <center>
          <center>
          <td width="66%" bgcolor="#E6E6FF">
            <div align="center">
              <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td width="20%" align="center"><img border="0" src="perfecta.gif" width="15" height="15"><br>
                    <input type="radio" value="perfecta" checked name="opinion"></td>
                  <td width="20%" align="center"><img border="0" src="mbuena.gif" width="15" height="15"><br>
                <label>
        <input type="radio" value="mbuena" name="opinion"></label></td>
                  <td width="20%" align="center"><img border="0" src="buena.gif" width="15" height="15"><br>
                    <label><input type="radio" value="buena" name="opinion"></label></td>
                  <td width="20%" align="center"><img border="0" src="mala.gif" width="15" height="15"><br>
                    <label><input type="radio" value="mala" name="opinion"></label></td>
                  <td width="20%" align="center"><img border="0" src="mmala.gif" width="15" height="15"><br>
                    <label><input type="radio" value="mmala" name="opinion"></label></td>
                </tr>
              </table>
            </div>          </td>
          </tr>
        </center></center></center></center>
                  <tr>
                    <td width="34%" bgcolor="#E6E6FF">
                      <p align="right">Confirmar</td>
          <td width="66%" bgcolor="#E6E6FF">
            <p align="left"><input type="submit" value="E N V I A R" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; background-color: #FFFFFF; border: 1 solid #000080">
            <label><input type="reset" value="B O R R A R" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; background-color: #FFFFFF; border: 1 solid #000080"></label></td>
          </tr>
          </table>
  </div>                    </td>
                  </tr>
                </table><input type="hidden" name="fecha" value="<? echo(date("d/m/Y")); ?>"></form>
              </div>
        <p align=justify><? include("index.txt"?></p>
 </td></tr></table></label></fieldset>*</td>
            </tr>
          </table>      </td>
    </tr>
  </table>
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr>
        <td width="100%" bgcolor="#CCCCFF">
          <p align="center">Prohibida la copia total o parcial de esta web sin
          el consentimiento previo del autor.</td>
      </tr>
    </table>
    </center>
  </div>
</body></html>
  #2 (permalink)  
Antiguo 04/03/2009, 03:02
 
Fecha de Ingreso: mayo-2008
Mensajes: 253
Antigüedad: 16 años
Puntos: 8
Respuesta: integrar 2 archivos php en 1

Este es el segundo archivo

2- Insertar.php

Código PHP:
<html><head><script>function disableselect(e)
{  return false  }
function reEnable()
{  return true  }
//Si es Internet Explorer 4 o superior
document.onselectstart=new Function ("return false")
//si es Netscape6
if (window.sidebar)
{  document.onmousedown=disableselect
   document.onclick=reEnable  }</script><style>body         { font-family: tahoma; font-size: 8 pt }
.vol         { color: #0000FF }
.vol:hover   { text-decoration: underline; color: #800000 }
.mas         { color: #000000 }
.mas:hover   { text-decoration: none; color: #888888 }
a            { color: #FF0000; text-decoration: none }
a:hover      { color: #000080; text-decoration: underline }
table         { font-size: 8pt }
.boton       { background-color: #00B4FF; color: #FFFFFF; font-family: 
               verdana, arial, helvetica; font-size: 8.5pt; 
               border-left: 2px Solid #00D6FF; border-right: 2px Solid #0092DD; 
               border-top: 2px Solid #00D6FF; border-bottom: 2px Solid #0092DD }
.art         { clear: none; float: none; height: 100%; width: 100%; color: #FFFFFF; 
               text-decoration: none }
.art:hover   { background-color: #0099FF; clear: none; float: none; height: 100%; align: 
               center; width: 100%; color: #000080; text-decoration: none }
.nombre { color: #000088; text-decoration: none }
.nombre:hover { text-decoration: underline }
</style><title>Ommadawn , tu oportunidad de conocer a fondo a Mike Oldfield</title></head>
<body topmargin="0" leftmargin="0"><center>
  <table border="0" cellpadding="0" cellspacing="0" width="759">
    <tr>
      
    </tr>
  </table>
  </center>
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>

    </tr>
  </table>
  </center>
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td width="75%" valign="top" bgcolor="#FFE6FF">
        <center>
          <table border="0" cellpadding="0" cellspacing="0" width="90%" height="43">
            <tr>
              <td width="100%" height="43"><fieldset><legend></legend>
                <label>
        <center>
          <center><table cellpadding="0" cellspacing="0" width="60%" border="0"><tr><td width="100%">
                        </center></center>
        </center>
                  </center>
        <p align=justify>
        <?php

$fp
=fopen("index.txt","r+"); 
$anterior=fread($fp,filesize("index.txt"));
rewind($fp);
$nuevo "<b><font color=\"#000088\" size=\"2\"><a href=\"mailto:$HTTP_GET_VARS[email]\" class=\"nombre\">$HTTP_GET_VARS[nombre]</a> <font color=\"#0056F9\">($HTTP_GET_VARS[fecha])</font></font></b>&nbsp;&nbsp;<img src=\"$HTTP_GET_VARS[opinion].gif\" border=0><br><p align=justify>$HTTP_GET_VARS[comentario]<hr>";
$total $nuevo.$anterior;
if(
fwrite($fp,$total)) {
Echo 
"Gracias, tu comentario ha sido insertado correctamente. <p align=center><a href=index.php>Volver</a>";
}Else{
Echo 
"Error, por alguna razón desconocida no ha sido procesado su comentario. Compruebe que ha rellenado todos los campos e inténtelo de nuevo.";
}
fclose($fp);
?> 


<?php

$fp 
fopen("ultimo.txt","w"); 
if(
fwrite($fp"Último comentario en el libro de visitas:<p align=justify>$HTTP_GET_VARS[comentario]<br><br><b>Enviado por <a href=\"mailto:$HTTP_GET_VARS[email]\">$HTTP_GET_VARS[nombre]</a></b><p align=right><b><a href=\"libro/index.php\" class=vol>Ver más</a></b>")){
Echo 
" ";
}Else{
Echo 
" ";
}
fclose($fp);
?></p>
 </td></tr></table></label></fieldset> </td>
            </tr>
          </table>      </td>
    </tr>
  </table>
  </body></html>
Bien todo esto funciona de maravilla subiendolo al servidor, pero ahora viene mi gran problema, dilema y agobio ¿puedo unir estos 2 archivos en 1?, estoy intentandolo desde hace días y no lo consigo con mas manuales de php que me leo, necesito que este todo en 1 . Muchas gracias maestros y espero me puedan ayudar.
  #3 (permalink)  
Antiguo 04/03/2009, 03:29
 
Fecha de Ingreso: enero-2008
Mensajes: 52
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: integrar 2 archivos php en 1

Bueno el codigo HTML es un cagarro, pero bueno he hecho lo mejor que he podido. Tampoco tengo tiempo ara de depurar el html. Le he puesto un name al boton enviar (addComentario) y en donde va el formulario le he puesto un if, que si se envia el post pues que salga lo que hay en insertar.php sino pues mostrara el formulario.

Código PHP:
<html><head><script>function disableselect(e)
{  return false  }
function reEnable()
{  return true  }
//Si es Internet Explorer 4 o superior
document.onselectstart=new Function ("return false")
//si es Netscape6
if (window.sidebar)
{  document.onmousedown=disableselect
   document.onclick=reEnable  }</script><style>body         { font-family: tahoma; font-size: 8 pt }
.vol         { color: #0000FF }
.vol:hover   { text-decoration: underline; color: #800000 }
.mas         { color: #000000 }
.mas:hover   { text-decoration: none; color: #888888 }
a            { color: #FF0000; text-decoration: none }
a:hover      { color: #000080; text-decoration: underline }
table         { font-size: 8pt }
.boton       { background-color: #00B4FF; color: #FFFFFF; font-family: 
               verdana, arial, helvetica; font-size: 8.5pt; 
               border-left: 2px Solid #00D6FF; border-right: 2px Solid #0092DD; 
               border-top: 2px Solid #00D6FF; border-bottom: 2px Solid #0092DD }
.art         { clear: none; float: none; height: 100%; width: 100%; color: #FFFFFF; 
               text-decoration: none }
.art:hover   { background-color: #0099FF; clear: none; float: none; height: 100%; align: 
               center; width: 100%; color: #000080; text-decoration: none }
.nombre { color: #000088; text-decoration: none }
.nombre:hover { text-decoration: underline }
</style><title>Ommadawn , tu oportunidad de conocer a fondo a Mike Oldfield</title></head>
<body topmargin="0" leftmargin="0"><center>
</center>
  <center>
  </center>
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td width="75%" valign="top" bgcolor="#FFE6FF">
        <center>
          <table border="0" cellpadding="0" cellspacing="0" width="60%" height="43">
            <tr>
              <td width="100%" height="43"><fieldset><legend></legend>
                <label>
        <center>
          <center><table cellpadding="0" cellspacing="0" width="90%" border="0"><tr><td width="100%">
              <div align="center">
                  <?php
                  
                  
if (isset($_GET["addComentario"])){
                        
$fp=fopen("index.txt","r+"); 
                        
$anterior=fread($fp,filesize("index.txt"));
                        
rewind($fp);
                        
$nuevo "<b><font color=\"#000088\" size=\"2\"><a href=\"mailto:$HTTP_GET_VARS[email]\" class=\"nombre\">$HTTP_GET_VARS[nombre]</a> <font color=\"#0056F9\">($HTTP_GET_VARS[fecha])</font></font></b>&nbsp;&nbsp;<img src=\"$HTTP_GET_VARS[opinion].gif\" border=0><br><p align=justify>$HTTP_GET_VARS[comentario]<hr>";
                        
$total $nuevo.$anterior;
                        if(
fwrite($fp,$total)) {
                        Echo 
"Gracias, tu comentario ha sido insertado correctamente. <p align=center><a href=index.php>Volver</a>";
                        }Else{
                        Echo 
"Error, por alguna razón desconocida no ha sido procesado su comentario. Compruebe que ha rellenado todos los campos e inténtelo de nuevo.";
                        }
                        
fclose($fp);
                        
                        
$fp fopen("ultimo.txt","w"); 
                        if(
fwrite($fp"Último comentario en el libro de visitas:<p align=justify>$HTTP_GET_VARS[comentario]<br><br><b>Enviado por <a href=\"mailto:$HTTP_GET_VARS[email]\">$HTTP_GET_VARS[nombre]</a></b><p align=right><b><a href=\"libro/index.php\" class=vol>Ver más</a></b>")){
                        echo 
" ";
                        }Else{
                        echo 
" ";
                        }
                        
fclose($fp);
                  }
                  else{
                          
?>
                        <form method="GET"><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#CCCCFF">
                              <tr>
                                <td width="100%">
                                  <div align="center">
                                    <table border="0" cellpadding="2" cellspacing="1" width="100%">
                                      <tr>
                                        <td width="100%" colspan="2" bgcolor="#CCCCFF">
                                          <p align="center"><b><font size="2">Deja tu comentario</font></b></td>
                                      </tr>
                                    </center></center>
                    </center>
                              </center>
                              <tr>
                                <td width="34%" bgcolor="#E6E6FF">
                                  <p align="right">Tu nombre</td>
              <center>
                    <center>
                    <center>
                      <center>
                      <td width="66%" bgcolor="#E6E6FF"><input type="text" name="nombre" size="20" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></td>
                      </tr>
                      </center></center>
                    </center>
                              </center>
                              <tr>
                                <td width="34%" bgcolor="#E6E6FF">
                                  <p align="right">Tu email</td>
              <center>
                    <center>
                    <center>
                      <center>
                      <td width="66%" bgcolor="#E6E6FF"><label><input type="text" name="email" size="20" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></label></td>
                      </tr>
                      </center></center>
                    </center>
                              </center>
                              <tr>
                                <td width="34%" bgcolor="#E6E6FF">
                                  <p align="right">Comentario</td>
              <center>
                    <center>
                    <center>
                      <center>
                      <td width="66%" bgcolor="#E6E6FF"><textarea rows="2" name="comentario" cols="50" style="font-family: 'Trebuchet MS', arial; font-size: 8 pt; color: #000000; border: 1 solid #000080"></textarea></td>
                      </tr>
                      </center></center>
                    </center>
                              </center>
                              <tr>
                                <td width="34%" bgcolor="#E6E6FF">
                                  <p align="right">Opinión sobre la web</td>
              <center>
                    <center>
                    <center>
                      <center>
                      <td width="66%" bgcolor="#E6E6FF">
                        <div align="center">
                          <table border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                              <td width="20%" align="center"><img border="0" src="perfecta.gif" width="15" height="15"><br>
                                <input type="radio" value="perfecta" checked name="opinion"></td>
                              <td width="20%" align="center"><img border="0" src="mbuena.gif" width="15" height="15"><br>
                            <label>
                    <input type="radio" value="mbuena" name="opinion"></label></td>
                              <td width="20%" align="center"><img border="0" src="buena.gif" width="15" height="15"><br>
                                <label><input type="radio" value="buena" name="opinion"></label></td>
                              <td width="20%" align="center"><img border="0" src="mala.gif" width="15" height="15"><br>
                                <label><input type="radio" value="mala" name="opinion"></label></td>
                              <td width="20%" align="center"><img border="0" src="mmala.gif" width="15" height="15"><br>
                                <label><input type="radio" value="mmala" name="opinion"></label></td>
                            </tr>
                          </table>
                        </div>          </td>
                      </tr>
                              <tr>
                                <td width="34%" bgcolor="#E6E6FF">
                                  <p align="right">Confirmar</td>
                      <td width="66%" bgcolor="#E6E6FF">
                        <p align="left"><input type="submit" name="addComentario" value="E N V I A R" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; background-color: #FFFFFF; border: 1 solid #000080">
                        <label><input type="reset" value="B O R R A R" style="font-family: 'Trebuchet MS', Arial; font-size: 8 pt; color: #000000; background-color: #FFFFFF; border: 1 solid #000080"></label></td>
                      </tr>
                      </table>
              </div>                    </td>
                              </tr>
                            </table><input type="hidden" name="fecha" value="<? echo(date("d/m/Y")); ?>"></form>
                        <?php
                  
}
                     
?>
              </div>
        <p align=justify><? include("index.txt"?></p>
 </td></tr></table></label></fieldset>*</td>
            </tr>
          </table>      </td>
    </tr>
  </table>
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr>
        <td width="100%" bgcolor="#CCCCFF">
          <p align="center">Prohibida la copia total o parcial de esta web sin
          el consentimiento previo del autor.</td>
      </tr>
    </table>
    </center>
  </div>
</body></html>
__________________
David Rojo Artículos de fiesta

Última edición por seiferdrg; 04/03/2009 a las 04:00
  #4 (permalink)  
Antiguo 04/03/2009, 03:43
 
Fecha de Ingreso: mayo-2008
Mensajes: 253
Antigüedad: 16 años
Puntos: 8
Respuesta: integrar 2 archivos php en 1

Hola seiferdrg gracias por tu pronta respuesta y ayuda, lo he probado y no va no se porque pero muchas gracias
  #5 (permalink)  
Antiguo 04/03/2009, 04:01
 
Fecha de Ingreso: enero-2008
Mensajes: 52
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: integrar 2 archivos php en 1

Prueba ahora, le he cambiado el action del form y le puesto el if con el $_GET. Yo no lo puedo probar por que mi ordena me esta haciendo el tonto y no me ejecuta bien los php.
__________________
David Rojo Artículos de fiesta
  #6 (permalink)  
Antiguo 04/03/2009, 04:15
 
Fecha de Ingreso: mayo-2008
Mensajes: 253
Antigüedad: 16 años
Puntos: 8
Respuesta: integrar 2 archivos php en 1

seiferdrg eres un solete , me sigue sin funcionar me sale error, pero no quiero molestarte mas ya lo has intentado 2 veces y eso es de admirar como pretendes ayudar. Lo que voy a hacer es buscar un libro de firmas o un sistema de comentarios para noticias que este integrado en 1 solo archivo php para poder incluirlo en el html. De veras muchas muchas gracias. Muackis
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 17:09.