0% encontró este documento útil (0 votos)
68 vistas11 páginas

EJEMPLOS BASICOS DE PHP Cake

El documento contiene varios ejemplos de código PHP que declaran y manipulan variables, imprimen tablas y texto, y usan condicionales if/else. Incluye ejemplos de formularios HTML, métodos GET y POST, y arrays.

Cargado por

Jeff Dk Gamboa
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
68 vistas11 páginas

EJEMPLOS BASICOS DE PHP Cake

El documento contiene varios ejemplos de código PHP que declaran y manipulan variables, imprimen tablas y texto, y usan condicionales if/else. Incluye ejemplos de formularios HTML, métodos GET y POST, y arrays.

Cargado por

Jeff Dk Gamboa
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 11

PHP Declaracin de Variable

Primera

Clase
<html>
<head>
<title>hola</title>
</head>
<body>
<?php
$ini= "hola";
$fin = " a todos";
$todo= $ini.$fin;
$numero1=2;
$numero2=5;
echo $todo;
echo $numero1*$numero2;
echo $numero1+$numero2;
?>
</body>
</html>

___________________
(Falta)
<?php
echo "<table border=1>";
$n=1;
for($n1=1; $n1<=10; $n1++){
echo "<tr>";
for($n2=1; $n2<=10; $n2++){
echo "<td>", $n, "</td>";
$n=$n+1;
}
echo "</tr>";
}
echo "</table>";

$a=5;
$b=6;
echo "valor de a: ".$a. " valor de b: ".$b ."<br>";
if($a<$b){
echo $a." es menor que ".$b;
}else{
echo $b." es menor que ".$a;
}
?>

<?php
$a=$_POST['a'];
$b=$_POST['b'];
echo "valor de a: ".$a. " valor de b: ".$b ."<br>";
if($a<$b){
echo $a." es menor que ".$b;
}else{
echo $b." es mayor que ".$a;
}
?>
.
<?php
$a=8;
$b=6;
echo "valor de a: ".$a. " valor de b: ".$b ."<br>";
if($a<$b){
echo $a." es menor que ".$b;
}else{
echo $b." es menor que ".$a;
}
?>
_____________________
Segunda Clase

<?php
echo $_POST['num1']."<br>";
echo $_request['num2'];
?>
.
<html>
<head>
<title>
Ejemplo
</title>
</head>
<body>
<h1> Ejemplo de formulario </h1>
<form action="4.php" method="GET">
Ingerse numero 1:<input type ="text" name="num1">
<br>
Ingerse numero 2:<input type ="text" name="num2">
<br>
<input type ="submit" name="submit" value="Enviar"/>
</form>
</body>
</html>

<html>
<head>
<title>
Ejemplo
</title>
</head>
<body>
<h1> Ejemplo de formulario </h1>
<form action="4.php" method="POST">
Ingerse numero 1:<input type ="text" name="num1">
<br>
Ingerse numero 2:<input type ="text" name="num2">
<br>
<input type ="submit" name="submit" value="Enviar"/>
</form>
</body>
</html>
..
localhost/php/4.php?num1=12&num2=2&submit=Enviar
Tercera clase
<?php
$dia=array(domingo, lunes, martes,mircoles,jueves
,viernes,sabado);
Echo $dia[2];
?>

<?php
define ('TAN','10');
echo "<table border=1>";
$n=1;
for($n1=1;$n1<=TAN;$n1++)
{
if($n1 %2==0)
echo "<tr bgcolor=#bdc3d6>";
else
echo "<tr bgcolor=red>";
for($n2=1;$n2<=TAN;$n2++)
{
echo "<td>" , $n. "</td>";
$n=$n+1;
}
echo "</tr>";
}
echo "</table>";
?>
.
<?php
define ('TAN','10');
echo "<table border=1>";
$n=1;
for($n1=1;$n1<=TAN;$n1++)
{
if($n1 %2==0)
echo "<tr bgcolor=yellow>";
else
echo "<tr bgcolor=red>";
for($n2=1;$n2<=TAN;$n2++)
{
echo "<td>" , $n. "</td>";
$n=$n+1;
}
echo "</tr>";
}
echo "</table>";
?>

<html>
<head><title> Ejemplo1 </title></head>
<body>
<h1> Ejemplo de Formulario </h1>
<form action=7.php method=POST>
<input type=radio name=genero value =0> Sr.
<input type=radio name=genero value =1> Sra. <br>
Tu apellido : <br>
<input type =text name=apellido>
<input type =submit name= submit value=Enviar />
</form>
</body>
</html>
..
<?php
If($_POST[genero] ==0){
Echo Hola Sr. ;
}
Else
{
Echo Hola Sra. ;
}
Echo <b>{$_POST['apellido']}</b>,<br> encantado de conocerte.;
?>
..
Tarea

<html>
<head><title> Ejemplo1 </title></head>
<body>
<h1> Formulario </h1>
<form action="18.php" method="POST">
Tu nombre : <br><br>
<input type ="text" name="nombre">
<br align="nombre"</br>
Tu apellido : <br><br>
<input type ="text" name="apellido">
<br align="apellido"</br>
<h5> 1.Cuantos planetas hay en nuestro sistema solar?</h5>
<input type="radio" name="altenativa1" value ="0"> 8
<input type="radio" name="altenativa1" value ="1"> 9
<input type="radio" name="altenativa1" value ="2"> 7
<input type="radio" name="altenativa1" value ="3"> N.A <br>
<h5> 2.Los Quelanios son: </h5>
<input type="radio" name="estado" value ="0"> ranas
<input type="radio" name="estado" value ="1"> culebras
<input type="radio" name="estado" value ="2"> tortugas
<input type="radio" name="estado" value ="3"> N.A <br>
<input type ="submit" name="submit" value="Enviar"/>
</form>
</body>
</html>
..
<?php
echo $_POST['nombre']."<br>";
echo $_REQUEST['apellido']."<br>";
If($_POST['altenativa1'] ==0 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==1){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==2 ){
echo "Ganaste ";
}
If($_POST['altenativa1'] ==3 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==0 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==1 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==2){
echo "Ganaste ";
}
If($_POST['altenativa1'] ==3 ){
echo "Vuelve a intentarlo ";
}
?>
..

<html>
<head><title> Ejemplo1 </title></head>
<body>
<h1> Formulario </h1>
<form action="18.php" method="POST">
Tu nombre : <br><br>
<input type ="text" name="nombre">
<br align="nombre"</br>
Tu apellido : <br><br>
<input type ="text" name="apellido">
<br align="apellido"</br>
<h5> 1.Cuantos planetas hay en nuestro sistema solar?</h5>
<input type="radio" name="altenativa1" value ="0"> 8
<input type="radio" name="altenativa1" value ="1"> 9
<input type="radio" name="altenativa1" value ="2"> 7
<input type="radio" name="altenativa1" value ="3"> N.A <br>
<h5> 2.Los Quelanios son: </h5>
<input type="radio" name="estado" value ="0"> ranas
<input type="radio" name="estado" value ="1"> culebras
<input type="radio" name="estado" value ="2"> tortugas
<input type="radio" name="estado" value ="3"> N.A <br>
<input type ="submit" name="submit" value="Enviar"/>
</form>
</body>
</html>

<?php
echo $_POST['nombre']."<br>";
echo $_REQUEST['apellido']."<br>";
If($_POST['altenativa1'] ==0 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==1){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==2 ){
echo "Ganaste ";
}
If($_POST['altenativa1'] ==3 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==0 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==1 ){
echo "Vuelve a intentarlo ";
}
If($_POST['altenativa1'] ==2){
echo "Ganaste ";
}
If($_POST['altenativa1'] ==3 ){
echo "Vuelve a intentarlo ";
}
?>
----****-----

http://localhost/php/4.php?num1=12&num2=2&submit=Enviar
<html>
<head>
<title>
Ejemplo
</title>
</head>
<body>
<? php
$ini="hola";
$fin=" a Todos";
$todo=$ini.$fin;
echo $Todo;
?>

<php
echo "<table border =1>";
$n=1;
for($n1=1; $n1<=10; $n1++)
{
echo"<tr>";
for($n2=1;$n2<10; $n2++)
}
echo"<td>",$n,"<7""</td>";
$n=$n+1;
}
echo "</tr>";
}
echo"</table>";
?>

<?php
$ini=5;
$fin=6;
$todo=$ini+$fin;
$echo$todo;
?>

<?php
$a=8;
$b=6;
echo "valor de a :".$a."Valor de b:".$b."<br>";
if($a<$b)
{
echo "a es menor que b";
}
else
{
echo"b es menor que a";
}
?>

También podría gustarte