Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/03/2008, 19:48
okram
Invitado
 
Mensajes: n/a
Puntos:
Re: formulario y action en un mismo php

Pues ya tienes un if($_POST['Agregar']), que se ejecuta sólo cuando se envia el formulario. Ahi muestras el mensaje, y después, dentro de un else{} colocas el formulario, que será mostrado sólo si $_POST['Agregar'] no ha sido definido, osea no se he enviado ningún formulario:

Código PHP:
<html>
<head>
<title></title>
</head>
<body>
<?php
include("config.php");
if(
$_POST[Agregar])
{
 
// Se ha enviado el formulario
 
$query="insert into equipos(nombre_equipo, nombre_escuela, integrante01, integrante02, integrante03, integrante04, integrante05, semestre, telefono, mail) values 
('$_REQUEST[equipo]', '$_REQUEST[escuela]', '$_REQUEST[integrante01]', '$_REQUEST[integrante02]', '$_REQUEST[integrante03]', '$_REQUEST[integrante04]','$_REQUEST[integrante05]','$_REQUEST[semestre]','$_REQUEST[telefono]','$_REQUEST[mail]')"
;
 
$Result=mysql_query($query);
mysql_close($conecta);
 
// Mensaje
echo 'Se guardaron los datos';
 
} else {
 
//Si no se ha enviado ningún formulario, lo muestras
?>
 
<p><strong>ALTAS</strong></p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="">
 
<p>&nbsp;</p>
...............
 
<table width="155" border="1" cellspacing="5" align="center">
<tr>
<td width="65"><input type="submit" name="Agregar" value="Agregar" /></td>
<td width="87"><input type="submit" name="Cancelar" value="Cancelar" /></td>
</tr>
</form>
<?php
// Cierre del if...else
}
?>
Otra forma sin tantas llaves es usando el comando exit;:

Código PHP:
<html>
<head>
<title></title>
</head>
<body>
<?php
include("config.php");
 
if(
$_POST[Agregar])
{
 
$query="insert into equipos(nombre_equipo, nombre_escuela, integrante01, integrante02, integrante03, integrante04, integrante05, semestre, telefono, mail) values 
('$_REQUEST[equipo]', '$_REQUEST[escuela]', '$_REQUEST[integrante01]', '$_REQUEST[integrante02]', '$_REQUEST[integrante03]', '$_REQUEST[integrante04]','$_REQUEST[integrante05]','$_REQUEST[semestre]','$_REQUEST[telefono]','$_REQUEST[mail]')"
;
 
$Result=mysql_query($query);
mysql_close($conecta);
 
echo 
'Formulario enviado';
 
// Terminamos la ejecución del script
exit;
 
}
?>
<p><strong>ALTAS</strong></p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="">
 
<p>&nbsp;</p>
........
 
<table width="155" border="1" cellspacing="5" align="center">
<tr>
<td width="65"><input type="submit" name="Agregar" value="Agregar" /></td>
<td width="87"><input type="submit" name="Cancelar" value="Cancelar" /></td>
</tr>
</form>
 
 
 
</body>
</html>
Un saludo,