Mostrando entradas con la etiqueta PHP. Mostrar todas las entradas
Mostrando entradas con la etiqueta PHP. Mostrar todas las entradas

CONECTAR HTML CON BASE MYSQL EN PHP

CONECTAR HTML CON BASE MYSQL EN PHP
CREAR UNA CARPETA LLAMADA academia


1 crear archivo index.html

<!DOCTYPE html>

<html lang="es">

<head>
<title>Conexion a Base de datos</title>
<meta charset="utf-8" />

</head>

<body>

 <h1>BASE DE DATOS</h1>
 <form method="POST" action=2conexion.php">
 servidor: <input type="text" name="ser"/></br>
 usuario: <input type="text" name="usu"/></br>
 clave: <input type="text" name="pas"/></br>
 base de datos: <input type="text" name="bdb"/></br>
 digite la consulta: <input type="text" name="cons"/></br>

 <input type="submit" name="Conectar" vale="conectar" /><br><br>
 

<footer>
        Creado por alvaro
</footer>
</body>
</html>

2 crear archivo conexion.php para conectar datos

<?php
if (isset($_POST{"Conectar"]))
   { $ser=$_POST["ser"];
     $usu=$_POST["usu"];
     $pas=$_POST["pas"];
     $dbd=$_POST["dbd"];
     $cons=$_POST["cons"];
     include 'cone.php';
   
     $sql=new conecta ($ser,$usu,$pas,$dbd);
     $consu=$sql->CONSU($CONS);
     $num = mysqli_num_rows($consu);
     if ($num>0)
         { echo "table">;
           echo "<tr>";
           echo "<th> codigo </th><th> nombre </th>";
           echo "</tr>";
           while ($row=mysqli_fetch_array($consu))
               { echo "<tr>";
                 echo "<td>".$row['codest']."</td><td>".$row['nomest']."<td>";
                 echo "</tr>";
               }
           echo "</table>";
         }
         
   }

?>

3 crear archivo cone.php para conectar base

<?PHP
class conecta extends MYSQLi
 { public $host,$user,$password,$database,$connection;
   public function _construct($host,$user,$password,$database)
         { $this->host=$host;
           $this->user=$user;           
           $this->password=$password;
           $this->database=$database;
           $this->connect_me();
         }
   private function connect_me()
         { $this->connection=$this->connect($this->host,$this->user,
                                            $this->password,$this->database);
           if ($this->connect_error)
              die($this->connect_error);
         }
   public function consu($cond)
      { $result=$this->query($cons);
        if ($this->error)
           { return $this->error;
           }
        else
           { return $result;
           }
         }
  }
?>
         



TOMEN

TOMEN
<! doctype html>
<head><meta charset="utf-8">
<title>conexion a Base de Datos</title>
</head>
<body>
<h1>BASE DE DATOS</h1>
<form method="POST" action=2conexion.php">
servidor:<input type="text" name="ser"/>
usuario:<input type="text" name="usu"/>
clave:<input type="text" name="pas"/>
base de datos:<input type="text" name="bdb"/>
digite la consulta:<input type="text" name="cons"/><br>

<input type="submit" name="Conectar" vale="conectar" /><br><br>
</form>
</body>
</html>

Calculadora en php html

Calculadora en php html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>operaciones basicas</title>
    <link href="index.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <script src="index.js"></script>
    calculadora <br>
    <form action="resultado.php" method="post">
      ingrese primer numero <br>
      <input type="text" name="num1" />
      <select name="ope">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
      </select>
  <br> ingrese el segundo numero <br>
  <input type="text" name="num2"/>
  <input type="reset" value="Borrar"/>
   <input type="submit" value="Calcular ya"/>
  <?php
  if ($_POST["num1"] != "" and
      $_POST["num2"] != "" )
     {$op=$_POST["ope"];
       $n1=$_POST["num1"];
       $n2=$_POST["num2"];
      switch($op)
       { case"+": echo ($sum=$n1+$n2);break;
         case"-": echo ($res=$n1+$n2);break;
         case"*": echo ($mul=$n1+$n2);break;
         case"/": echo ($divi=$n1+$n2);break;
       
         }
     }
   
  else
  {
     echo ("debe ingresar un numero");
     echo ('<br><a href="resultado"> volver</a>');
   
  }
 
 ?>
 
   
</form>
</body>
</html>