Foros del Web » Programando para Internet » PHP »

solo ejecutar un php con sumit

Estas en el tema de solo ejecutar un php con sumit en el foro de PHP en Foros del Web. amigasos tengo el siguiente codigo ... Código PHP: <?php       session_start ();     include_once  "conexion.php" ; ?>   <?php          function  verificar_testm ( $rut ,& $result ...
  #1 (permalink)  
Antiguo 29/09/2012, 19:58
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
solo ejecutar un php con sumit

amigasos tengo el siguiente codigo ...

Código PHP:
<?php 
     session_start
();
    include_once 
"conexion.php";
?> 

<?php
   
    
function verificar_testm($rut,&$result)
    {
        
$sql "SELECT * FROM testm WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testm($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">ya la hizo</div>';
            }
            else
            {
                
header("location:a_mf1.php");
                
            }
        }
 
        
?>
  
<?php
   
    
function verificar_testl($rut,&$result)
    {
        
$sql "SELECT * FROM testl WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testl($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">ya la hizo</div>';
            }
            else
            {
                
header("location:a_lf1.php");
                
            }
        }
 
        
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/JavaScript">
var procedenciaValida = new Array(
"buscar_codigo1.php","area.php"
);
var ok = false;
for(i in procedenciaValida) {
if(document.referrer.indexOf(procedenciaValida[i]) > -1) {
ok = true; 
}
}
if(!ok) {
document.location.href="buscar_codigo1.php"; 
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <img src="portada1.jpg" alt="" width="1100" height="200" align="top" />
  <table width="1102" border="0">
    <tr>
      <td colspan="2" align="center"><p><strong>LAS AREAS DISPONIBLES SON LAS SIGUENTES</strong></p>
      <p>&nbsp;</p></td>
    </tr>
    <tr>
      <td width="539" align="right"><p>Codigo
        
      :</p>
        <p>
      Rut:      </p></td>
      <td width="553" align="left"><p>
        <input name="codigo" type="text"  value="<?php 
$cod 
$_GET["cod"]; 
echo 
"$cod"
?>" readonly="readonly"/>        
        </p>
        <p>
          <input name="rut" type="text"  value="<?php 
$rut 
$_GET["rut"]; 
echo 
"$rut"
?>" readonly="readonly"/>
      </p></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input name="matematicas2" type="submit" value="matematicas"/>
      <input name="lenguaje2" type="submit" value="lenguaje"/></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><img src="divisor1.png" width="1100" height="10" alt="" /></p>
</form>
</body>
</html>
la idea es que cuando se aprete el boton matematicas ejecute el php testm y cuando se aprete el lenguaje se ejecute el php testm si se dan cuentacada php direcciona a una web diferente ..

no se como hacerlo y ustedes me han ayudado mucho y rapido .. asi que porfa cualquier ayuda se los agradesco mucho

saludos y gracias por su tiempo
  #2 (permalink)  
Antiguo 29/09/2012, 20:29
Avatar de rodrigo791  
Fecha de Ingreso: noviembre-2009
Ubicación: Uruguay
Mensajes: 1.339
Antigüedad: 14 años, 5 meses
Puntos: 168
Respuesta: solo ejecutar un php con sumit

Y en al atributo action del form no piensa poner nada?
  #3 (permalink)  
Antiguo 29/09/2012, 22:02
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: solo ejecutar un php con sumit

Podes hacer lo siguiente:
1) Utilizar dos form por separado
2) O al los botones submit, dejarlos solo como buttons y mediante javascript enviar los datos a donde corresponda o poner algún identificador a la hora de enviar los datos para saber que botón se apretó.

Saludos
  #4 (permalink)  
Antiguo 29/09/2012, 22:35
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: solo ejecutar un php con sumit

sobre el atributo action. la verdad es que con un solo boton me funciona impecable tonses no lo eh colocado ...

sobre hacer los form separados lo entiedo .. pero como hago para que cada form use solo el php correspondiente... osea que el form donde esta el boton matematicas realize el php testm y el boton en el form lenguaje el php testl

es decir que se realice solo el php del boton correspondiente
  #5 (permalink)  
Antiguo 29/09/2012, 22:39
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: solo ejecutar un php con sumit

Cita:
Iniciado por KAKOROSAS Ver Mensaje
sobre el atributo action. la verdad es que con un solo boton me funciona impecable tonses no lo eh colocado ...

sobre hacer los form separados lo entiedo .. pero como hago para que cada form use solo el php correspondiente... osea que el form donde esta el boton matematicas realize el php testm y el boton en el form lenguaje el php testl

es decir que se realice solo el php del boton correspondiente
Donde dice action="" agregas entre las comillas, ?accion=testl o ?accion=testm segun corresponda, entonces el PHP quedaria de esta forma

if($_GET["accion"] == testl) {
ACA TODO LO QUE ES CON EL TESTL
} else {
ACA TESTM
}

Saludos
  #6 (permalink)  
Antiguo 30/09/2012, 18:20
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: solo ejecutar un php con sumit

no me funciona :(


Cita:
Iniciado por marcofbb Ver Mensaje
Donde dice action="" agregas entre las comillas, ?accion=testl o ?accion=testm segun corresponda, entonces el PHP quedaria de esta forma

if($_GET["accion"] == testl) {
ACA TODO LO QUE ES CON EL TESTL
} else {
ACA TESTM
}

Saludos
  #7 (permalink)  
Antiguo 30/09/2012, 19:02
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: solo ejecutar un php con sumit

Cita:
Iniciado por KAKOROSAS Ver Mensaje
no me funciona :(
Porque seguro algo mal hiciste, deja el código

Saludos
  #8 (permalink)  
Antiguo 30/09/2012, 20:10
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: solo ejecutar un php con sumit

gracias por el interes en ayudarme ...

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/JavaScript">
var procedenciaValida = new Array(
"buscar_codigo1.php","area.php"
);
var ok = false;
for(i in procedenciaValida) {
if(document.referrer.indexOf(procedenciaValida[i]) > -1) {
ok = true; 
}
}
if(!ok) {
document.location.href="buscar_codigo1.php"; 
}
</script>
</head>
<body>
>
  <img src="portada1.jpg" alt="" width="1100" height="200" align="top" />
   <form id="form1" name="form1" method="get" action="?accion=testm"/>
  <table width="1102" border="0">
    <tr>
      <td colspan="2" align="center"><p><strong>LAS AREAS DISPONIBLES SON LAS SIGUENTES</strong></p>
      <p><?php 
     session_start
();
    include_once 
"conexion.php";
?> 


<?php
if($_GET['action'] == "testm"){    
    function 
verificar_testm($rut,&$result)
    {
        
$sql "SELECT * FROM testm WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testm($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">Este Rut ya realizo el test de Matematicas</div>';
            }
            else
            {
                
$cod $_POST['cod'];
                
$rut $_POST['rut'];
                
header("location:testm1.php?cod=$cod&rut=$rut");
                
            }
        }
   } else {   
         
        
$sql "SELECT * FROM testl WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testl($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">Este Rut ya realizo el test de Lenguaje</div>';
            }
            else
            {
                
$cod $_POST['cod'];
                
$rut $_POST['rut'];
                
header("location:testl1.php?cod=$cod&rut=$rut");
                
            }
        }
   
            
        
?></p></td>
    </tr>
    <tr>
      <td width="539" align="right"><p>Codigo
        
      :</p>
        <p>
      Rut:      </p></td>
      <td width="553" align="left"><p>
        <input name="codigo" type="text"  value="<?php 
$cod 
$_GET["cod"]; 
echo 
"$cod"
?>" readonly="readonly"/>        
        </p>
        <p>
          <input name="rut" type="text"  value="<?php 
$rut 
$_GET["rut"]; 
echo 
"$rut"
?>" readonly="readonly"/>
      </p></td>
    </tr>
    <tr>
    
      <td align="right"><input name="matematicas" type="submit" value="Matematicas"/>
      <td align="left"><input name="lenguaje" type="submit" value="Lenguaje"/>
      </td>
    </tr>
  </table>
  </td><form/>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><img src="divisor1.png" width="1100" height="10" alt="" /></p>

</body>
</html>
  #9 (permalink)  
Antiguo 30/09/2012, 20:46
marcofbb
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: solo ejecutar un php con sumit

Porque te falto crear otro form para que actue con ?accion=testl
  #10 (permalink)  
Antiguo 01/10/2012, 06:42
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: solo ejecutar un php con sumit

Cita:
Iniciado por marcofbb Ver Mensaje
Porque te falto crear otro form para que actue con ?accion=testl
supongo que ahora est bien .. pero me sale esto

Notice: Undefined index: action in C:\xampp\htdocs\tab\area.php on line 34

no se que otro erros podria tener

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/JavaScript">
var procedenciaValida = new Array(
"buscar_codigo1.php","area.php"
);
var ok = false;
for(i in procedenciaValida) {
if(document.referrer.indexOf(procedenciaValida[i]) > -1) {
ok = true; 
}
}
if(!ok) {
document.location.href="buscar_codigo1.php"; 
}
</script>
</head>
<body>
>
  <img src="portada1.jpg" alt="" width="1100" height="200" align="top" />
  <table width="1102" border="0">
    <tr>
      <td colspan="2" align="center"><p><strong>LAS AREAS DISPONIBLES SON LAS SIGUENTES</strong></p>
      <p><?php 
     session_start
();
    include_once 
"conexion.php";
?> 


<?php
if($_GET['action'] == "testm") {
    function 
verificar_testm($rut,&$result)
    {
        
$sql "SELECT * FROM testm WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testm($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">Este Rut ya realizo el test de Matematicas</div>';
            }
            else
            {
                
$cod $_POST['cod'];
                
$rut $_POST['rut'];
                
header("location:testm1.php?cod=$cod&rut=$rut");
                
            }
        }
   } else {
   function 
verificar_testl($rut,&$result)
    {  
         
        
$sql "SELECT * FROM testl WHERE rut = '$rut'";
        
$rec mysql_query($sql);
        
$count 0;
        while(
$row mysql_fetch_object($rec))
        {
            
$count++;
            
$result $row;
        }
        if(
$count == 1)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
    
    if(isset(
$_POST['rut']))
        {
            if(
verificar_testl($_POST['rut'],$result) == 1)
            {
             echo 
'<div class="error">Este Rut ya realizo el test de Lenguaje</div>';
         }
            else
        {
                
$cod $_POST['cod'];
                
$rut $_POST['rut'];
                
header("location:testl1.php?cod=$cod&rut=$rut");
                
        }
        }
        }       
        
?></p></td>
    </tr>
    <tr>
      <td width="539" align="right"><p>Codigo
        
      :</p>
        <p>
      Rut:      </p></td>
      <td width="553" align="left"><p>
        <input name="codigo" type="text"  value="<?php 
$cod 
$_GET["cod"]; 
echo 
"$cod"
?>" readonly="readonly"/>        
        </p>
        <p>
          <input name="rut" type="text"  value="<?php 
$rut 
$_GET["rut"]; 
echo 
"$rut"
?>" readonly="readonly"/>
      </p></td>
    </tr>
    <tr>
    
    <td align="right"><form action="?action=testm" method="get" name="testm"><input name="matematicas" type="submit" value="Matematicas"/>
    </form>
             
      <td align="left"><form action="?action=testl" method="get" name="testl"><input name="lenguaje" type="submit" value="Lenguaje"/> </form>
     </td>
    </tr>
  </table>
  </td>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><img src="divisor1.png" width="1100" height="10" alt="" /></p>

</body>
</html>

Última edición por KAKOROSAS; 01/10/2012 a las 07:57
  #11 (permalink)  
Antiguo 01/10/2012, 13:45
 
Fecha de Ingreso: enero-2004
Mensajes: 72
Antigüedad: 20 años, 3 meses
Puntos: 1
Respuesta: solo ejecutar un php con sumit

sigo con el problemita .. porfis ayuda..

Etiquetas: html, mysql, sql
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 12:50.