Introducción a PHP , Casos y Actividad

 Ejemplos guia_01


Ejercicio

Lista.php

<!DOCTYPE html>
<html>
    <head> <title> Formulario carros </title> </head>
    <body>
        <h2> Seleccione marca de auto </h2>
        <form method="post" action="carros.php">
            Tipo: <br>
            <select name="tipo">
                <option value="Toyota"> Toyota Celica </option>
                <option value="Ford"> Ford Start </option>
                <option value="Hyundai"> Hyundai Tucson </option>
            </select>
            Color: <br>
            <input type="text" name="txtColor" />
            <input type="submit" />
        </form>
    </body>
</html>

Carros.php

<!DOCTYPE html>
<html>
    <head>
        <title> Usando Formulario carros </title>
    </head>
    <body>
        <h2> Obteniendo datos del Formulario </h2>
        <?php
//obtener datos de entrada del array contenedor
$tipo=$_POST["tipo"];
$color=$_POST["txtColor"];
echo "<br> Tu $tipo $color esta Ok";
?>
</body>
</html>





Ejercicios de experimentación y análisis


caso 01

Eje1.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
 <form method="POST" name="form1" action="eje1Recibe.php">
 Nombre:
<input type="text" name="nombre"> <br>
 Apellido:
<input type="text" name="apellido"> <br>
<input type="submit" value="Enviar">
</form>
</body>
</html>

eje1Recibe.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
$nom=$_REQUEST['nombre'];
$ape=$_REQUEST['apellido'];
echo $nom; echo "<br>";
echo $ape;
?>
</body>
</html>






caso 02



eje2.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje2Recibir.php" method="post">
 Digite primer valor:
<input type="text" name="valor1">
<br>
Digite segundo valor:
<input type="text" name="valor2">
<br>
<input type="radio" name="radio1" value="suma">sumar
<br>
<input type="radio" name="radio1" value="resta">restar
<br>
<input type="submit" name="operar">
</form>
</body>
</html>

eje2Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
if ($_REQUEST['radio1']=="suma")
{
$suma=$_REQUEST['valor1'] + $_REQUEST['valor2']; echo "La suma es:".$suma;
}
else
{
if ($_REQUEST['radio1']=="resta")
{
$resta=$_REQUEST['valor1'] - $_REQUEST['valor2']; echo "La resta es:".$resta;
}
}
?>
</body>
</html>





caso 03


Eje3.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje3Recibir.php" method="post">
Digite primer valor:
<input type="text" name="valor1">
<br>
Digite segundo valor:
<input type="text" name="valor2">
<br>
<input type="checkbox" name="check1">sumar
<br>
<input type="checkbox" name="check2">restar
<br>
<input type="submit" name="operar">
</form>
</body>
</html>

eje3Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
if (isset($_REQUEST['check1']))
{
$suma=$_REQUEST['valor1'] + $_REQUEST['valor2'];
 echo "La suma es:".$suma."<br>";
}
if (isset($_REQUEST['check2']))
{
$resta=$_REQUEST['valor1'] - $_REQUEST['valor2'];
 echo "La resta es:".$resta;
}
?>
</body>
</html>



caso 04

Eje4.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje4Recibir.php" method="post">
Digite primer valor:
<input type="text" name="valor1">
<br>
Digite segundo valor:
<input type="text" name="valor2">
<br>
<select name="operacion">
<option value="suma">sumar</option>
<option value="resta">restar</option>
</select>
<br>
<input type="submit" name="operar">
</form>
</body>
</html>

eje4Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
if ($_REQUEST['operacion']=="suma")
{
$suma=$_REQUEST['valor1'] + $_REQUEST['valor2']; echo "La suma es:".$suma;
}
else
{
if ($_REQUEST['operacion']=="resta")
{
$resta=$_REQUEST['valor1'] - $_REQUEST['valor2']; echo "La resta es:".$resta;
}
}
?>
</body>
</html>



caso 05

Eje5.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action=" eje5Recibir.php" method="post">
Digite nombre:<input type="text" name="nombre"><br>
Digite su curriculum:<br>
<textarea name="curriculum"></textarea>
<br>
<input type="submit" value="Confirmar">
</form>
</body>
</html>

eje5Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
echo "El nombre ingresado:".$_REQUEST['nombre']; echo "<br>";
echo "El curriculum:".$_REQUEST['curriculum'];
?>
</body>
</html>





caso 06

Eje6.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje6Recibir.php" method="post">
 Número 1:
<input type="text" name="numero1"><br>
Número 2:
<input type="text" name="numero2"><br>
Número 3:
<input type="text" name="numero3"><br>
<input type="submit" value="Operar">
</form>
</body>
</html>

eje6Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
$num1=$_REQUEST['numero1'];
$num2=$_REQUEST['numero2'];
$num3=$_REQUEST['numero3'];
$suma=$num1+$num2+$num3;
echo "La suma de $num1 + $num2 + $num3 es: $suma <br>";
if($num1==$num2 && $num2==$num3)
{ echo "Los números son iguales";
}else
{
echo "Los números no son iguales";
}
?>
</body>
</html>





caso 07

Eje7.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje7Recibir.php" method="post">
Digite un texto:<input type="text" name="texto"><br>
<input type="submit" value="Mostrar">
</form>
</body>
</html>

eje7Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
$texto=$_REQUEST['texto'];
for($x=0;$x<10;$x++)
{ echo "$texto<br>";
}
?>
</body>
</html>




caso 08

Eje8.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje8Recibir.php" method="post">
Digite número:<input type="text" name="numero"><br>
<input type="submit" value="Mostrar tabla">
</form>
</body>
</html>

eje8Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
$num=$_REQUEST['numero'];
echo "<table border=1 width=100%>"; echo "<tr>";
echo "<td>";
echo "Tabla de multiplicar"; echo "<hr>"; for($x=0;$x<=12;$x++){
$res=$x*$num;
echo "$x por $num es $res <br>";
}
echo "</td>";
echo "<td>";
echo "<br><br>Tabla de la suma"; echo "<hr>"; for($x=0;$x<=12;$x++){
$res=$x+$num;
echo "$x más $num es $res <br>";
}
echo "</td>";
echo "</tr>"; echo "</table>";
?>
</body>
</html>



caso 09

Eje9.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<form action="eje9Recibir.php" method="post">
 Usuario:
<input type="text" name="usuario"><br>
Password:
<input type="password" name="password"><br>
<input type="submit" value="Ingresar">
</form>
</body>
</html>

eje9Recibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>I.E.S. Pedro P. Diaz</title>
</head>
<body>
<?php
$usu=$_REQUEST['usuario'];
$pas=$_REQUEST['password'];
if($usu=="rosa" && $pas=="pedrito")
{ echo "<h2>Bienvenido al sistema</h2>";
echo "<hr>";
echo "*******************************<br>";
echo "*******************************<br>";
echo "*******************************<br>";
echo "*******************************<br>";
}else{
echo "Usted no tiene acceso<br>";
echo "<a href='eje1.php'> Volver </a>";
}
?>
</body>
</html>





TAREA


a)      Crear un programa que use formulario web para convertir de soles a dólares, euros

soles.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SOLES A DOLARES Y EUROS</title>
</head>
<body>
<form action="solesRecibir.php" method="post">
 INGRESE LA CANTIDAD EN SOLES
<input type="text" name="numero"><br>
<input type="submit" value="Operar">
</form>
</body>
</html>

solesRecibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SOLES A DOLARES Y EUROS</title>
</head>
<body>
<?php
$num1=$_REQUEST['numero'];
echo "SOLES ---> $num1 <br>";
$dolar=$num1*0.27;
$euro=$num1*0.25;
echo "en DOLARES = $dolar <br>";
echo "en EUROS = $euro";
?>
</body>
</html>





b)      Crear un programa que use formulario web para convertir de dólares a soles, euros

dolares.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOLARES A SOLES Y EUROS</title>
</head>
<body>
<form action="dolaresRecibir.php" method="post">
 INGRESE LA CANTIDAD EN DOLAReS
<input type="text" name="numero"><br>
<input type="submit" value="Operar">
</form>
</body>
</html>

dolaresRecibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOLARES A SOLES Y EUROS</title>
</head>
<body>
<?php
$num1=$_REQUEST['numero'];
echo "DOLARES ---> $num1 <br>";
$soles=$num1*3.77;
$euro=$num1*0.94;
echo "en SOLES = $soles <br>";
echo "en EUROS = $euro";
?>
</body>
</html>





c)      Crear un programa que use formulario web para convertir de euros a dólares, soles

euros.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>EUROS A SOLES Y DOLARES</title>
</head>
<body>
<form action="dolaresRecibir.php" method="post">
 INGRESE LA CANTIDAD EN EUROS
<input type="text" name="numero"><br>
<input type="submit" value="Operar">
</form>
</body>
</html>

eurosRecibir.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>EUROS A SOLES Y DOLARES</title>
</head>
<body>
<?php
$num1=$_REQUEST['numero'];
echo "DOLARES ---> $num1 <br>";
$soles=$num1*4.01;
$dolar=$num1*1.06;
echo "en SOLES = $soles <br>";
echo "en EUROS = $dolar";
?>
</body>
</html>








Comentarios