0% encontró este documento útil (0 votos)
12 vistas

Código Aplicación

Cargado por

celutelcelutek77
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 TXT, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
12 vistas

Código Aplicación

Cargado por

celutelcelutek77
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 TXT, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 7

Código de aplicación en PHP-JavaScript-HTML

Contiene las principales actividades Alta-Borrar-Modificar-Mostrar-Buscar alumnos,


profesores, materia, persona administrativo...
Desarrollado en Visual Studio Code, XAMP-MySQL,
Base de Datos
Metodología Modelo Vista Controlador

//Conexion.php
<?php
$host ="localhost";
$user = "root";
$clave = "";
$bd= "titulacion";
$conectar = mysqli_connect($host, $user, $clave, $bd);
?>

//alta_alumnos.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alta Alumnos </title>
</head>
<body>
<a href="alta_alumnos.html"> Alumnos </a> <a href="formapoyo.html"> Apoyo
</a><a href="alta_materia.html">Materias</a>
<a href="usuarios.html"> Usuarios </a> <a href="altaprofe.html">Docentes</a>
<a href="alta_admin.html"> Administrativos </a>
<a href="asistencia.php">Asistencia</a><a
href="alta_espe.html">Especialidad</a>
<a href="buscar.php">Buscar Alumno</a> <a href="des_sol_serv.html">Descarga
Solicitud S. S. </a>
<h1>Ingresar Alumnos</h1>
<fieldset>
<form method="POST" action="altaalumnos.php">
<label for="">Nombre: </label><br>
<input type="text" name="nombre" id="nombre" placeholder="Ingrese
nombre" required ><br><br>
<label for="">Apellido 1: </label><br>
<input type="text" name="ape1" id="ape1" placeholder="Ingrese apellido
1" required ><br><br>
<label for="">Apellido 2: </label><br>
<input type="text" name="ape2" id="ape2" placeholder="Ingrese apellido
2" required ><br><br>
<label for="">Sexo: </label><br>
<input type="text" name="sexo" id="sexo" placeholder="Ingrese sexo"
required ><br> <br>
<label for="">Núm. Control: </label><br>
<input type="text" name="nocontrol" id="nocontrol" placeholder="Ingrese
número control" required ><br> <br>
<button type="submit">Guardar</button><br><br>
<button type="button"><a href="alumnosmuestra.php"> Consultar Alumnos
</a></button>
</form>
</fieldset>
</body>
</html>
//altaalumnos.php
<?php
include 'conexion.php';
$nombre = $_POST['nombre'];
$ape1 = $_POST['ape1'];
$ape2 = $_POST['ape2'];
$sexo = $_POST['sexo'];
$control=$_POST['nocontrol'];
$insertar = "INSERT INTO alumnos VALUES('', '$nombre', '$ape1', '$ape2',
'$sexo', '$control')";
$query = mysqli_query($conectar, $insertar);
if($query){
echo "<script> alert ('Correcto');
location.href = 'alta_alumnos.html';
</script>";
} else{
echo "<script> alert ('Incorrecto');
location.href = 'alta_alumnos.html';
</script>";
}
?>

//mostraralumnos.php
<?php
include 'consultaalumnos.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Consulta Alumnos</title>
<script type="text/javascript">
function confirmar(){ <!--Función para confirmar eliminar-->
return confirm('¿Deseas eliminar, estas seguro?');
}
</script>
</head>
<body>
<a href="alta_alumnos.html"> Alumnos </a> <a href="formapoyo.html"> Pers. Apoyo
</a><a href="alta_materia.html">Materias</a>
<a href="usuarios.html"> Usuarios </a> <a href="altaprofe.html">Docentes</a> <a
href="alta_admin.html">Administrativos</a>
<a href="asistencia.php">Asistencia</a>
<h1>Información de Alumnos</h1>
<br>
<table border="1">
<thead >
<tr>
<th>ID:</th>
<th>Nombre:</th>
<th>Apellido 1:</th>
<th>Apellido 2:</th>
<th>Sexo:</th>
<th>No. Control</th>
<th>Editar: </th>
<th>Eliminar: </th>
</tr>
</thead>
<tbody id="datos">
<?php
foreach($query as $row){ ?>
<tr> <!--Referencia campos de Base de Datos-->
<td><?php echo $row['id_alumno']; ?></td>
<td><?php echo $row['nombre']; ?></td>
<td><?php echo $row['ape1']; ?></td>
<td><?php echo $row['ape2']; ?></td>
<td><?php echo $row['sexo']; ?></td>
<td><?php echo $row['nocontrol']; ?></td>
<td><?php echo "<a href='alumnosactualizar.php?id=".$row['id_alumno']."'>
Editar </a>"; ?> </td>
<td><?php echo "<a href='eliminaralumnos.php?id=".$row['id_alumno']."'
onclick ='return confirmar()'> Eliminar </a>"; ?> </td>
</tr> <!--Referencia eliminar alumnos.php-->
</tbody>
<?php
}
?>
</table> <br>
<button type="button"><a href="alta_alumnos.html"> Regresar </a></button>
</body>
</html>

//consultaalumnos.php
<?php
include 'conexion.php';
$consultar ="SELECT * FROM alumnos ";
$query = mysqli_query($conectar, $consultar);
$array = mysqli_fetch_array($query);
?>

//actualizaralumnos.php
<?php
include "conexion.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Actualizar Alumnos</title>
</head>
<body> <!--Esta sección obtiene los valores cambiados en formulario -->
<?php
if(isset($_POST['enviar'])){ //"enviar" viene del mismo formuario atributo
name "enviar"
$id=$_POST['id'];
$nombre=$_POST['nombre'];
$ape1 = $_POST['ape1']; //valores vienen del atributo name del mismo
formulario
$ape2 = $_POST['ape2'];
$sexo = $_POST['sexo'];
$sql ="UPDATE alumnos set nombre='$nombre', ape1 = '$ape1', ape2 = '$ape2',
sexo = '$sexo' where id_alumno = '$id' ";
mysqli_query($conectar, $sql);
if($sql){
echo "<script> alert ('Actualizado');
location.href = 'alumnosmuestra.php';
</script>";
} else{
echo "<script> alert ('Incorrecto');
location.href = 'alumnosmuestra.php';
</script>";
}
} else{ //Esta sección obtiene los valores de la base de datos y los
mostramos en el formulario
$id=$_GET['id']; //valor id viene del formulario mostrar alumnos
$sql="SELECT * from alumnos where id_alumno = '".$id."' ";
$resultado=mysqli_query($conectar, $sql);
$row=mysqli_fetch_assoc($resultado);
$nombre = $row['nombre'];
$ape1 = $row['ape1'];
$ape2 = $row['ape2']; //valor viene de base de datos
$sexo = $row['sexo'];
mysqli_close($conectar);
?>
<a href="alta_alumnos.html"> Alumnos </a> <a href="formapoyo.html"> Per. Apoyo
</a><a href="alta_ateria.html">Materias</a>
<a href="usuarios.html"> Usuarios </a> <a href="altaprofe.html">Docentes</a>
<a href="alta_admin.html">Administrativos</a>
<h1>Modificando Alumnos</h1>
<fieldset>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<label for="">Nombre: </label><br>
<input type="text" name="nombre" value="<?php echo $nombre; ?>"
><br><br>
<label for="">Apellido 1: </label><br>
<input type="text" name="ape1" value="<?php echo $ape1; ?>" ><br><br>
<label for="">Apellido 2: </label><br>
<input type="text" name="ape2" value="<?php echo $ape2; ?>" ><br><br>
<!--variable $ape2 viene de sección obtiene valores de BD-->
<label for="">Sexo: </label><br>
<input type="text" name="sexo" value="<?php echo $sexo; ?>" ><br> <br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="enviar" id="" value="ACTUALIZAR"> <br><br>
</form>
</fieldset>
<button type="button"><a href="alumnosmuestra.php"> Consultar Alumnos
</a></button>
<?php } ?>
</body>
</html>

//eliminaralumnos.php
<?php
include 'conexion.php';
$id= $_GET['id'];

$sql = "DELETE FROM alumnos WHERE id_alumno ='".$id."' ";


$resultado = mysqli_query($conectar, $sql);
if($resultado){
echo "<script> alert ('Eliminado correctamente');
location.href ='alumnosmuestra.php';
</script>";
} else {
echo "<script> alert ('Error al eliminar ');
location.href ='alumnosmuestra.php';
</script>";
}
?>

//Buscar_Alumnos.php

<?php include 'conexion.php'; ?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Buscar</title>
</head>
<body>
<h1> Busqueda de Alumnos FUNCIONA!!</h1> <h2>Realizaron su Servicio Social</h2>
<a href="alta_alumnos.html">Alumnos</a> <a href="altaprofe.html">Docentes</a>
<a href="usuarios.html">Usuarios</a>
<a href="formclientes.html">Pers. Apoyo</a> <a
href="alta_admin.html">Administrativos</a>
<a href="buscar.php">Buscar Alumno</a> <a href="des_sol_serv.html">Descarga
Solicitud S. S. </a><br><br>

<fieldset>
<form action="" method="GET">
<label for="">Buscar por nombre, número de control,
apellidos</label><br><br>
<input type="text" name="buscar" id="" placeholder="Ingrese dato de
alumno"><br><br>
<input type="submit" name="btnbuscar" value="Buscar">
<br><br>
<table >
<thead>
<th>Nombre:</th>
<th>Apellido 1:</th>
<th>Apellido 2:</th>
<th>Sexo:</th>
<th>Núm.Control:</th>
</thead>
<tbody>
<?php
if(isset($_GET['btnbuscar'])){
$busqueda = $_GET['buscar'];
$consulta= $conectar -> query ("SELECT * from alumnos where nocontrol LIKE
'%$busqueda%' or nombre LIKE '%$busqueda%' or ape1 LIKE '%$busqueda%' or ape2 LIKE
'%$busqueda%' ");
while($row = $consulta -> fetch_array()){
?>
<tr>
<td><?php echo $row['nombre']; ?></td>
<td><?php echo $row['ape1'];?></td>
<td><?php echo $row['ape2'];?></td>
<td><?php echo $row['sexo'];?></td>
<td><?php echo $row['nocontrol'];?></td>
</tr>
<?php }
}
?>
</tbody>
</table>
</form>
</fieldset>
</body>
</html>

//buscar.php
<?php include 'conexion.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Buscar</title>
</head>
<body>
<h1> Busqueda de Alumnos FUNCIONA!!</h1> <h2>Realizaron su Servicio Social</h2>
<a href="alta_alumnos.html">Alumnos</a> <a href="altaprofe.html">Docentes</a>
<a href="usuarios.html">Usuarios</a>
<a href="formclientes.html">Pers. Apoyo</a> <a
href="alta_admin.html">Administrativos</a>
<a href="buscar.php">Buscar Alumno</a> <a href="des_sol_serv.html">Descarga
Solicitud S. S. </a><br><br>
<fieldset>
<form action="" method="GET">
<label for="">Buscar por nombre, número de control,
apellidos</label><br><br>
<input type="text" name="buscar" id="" placeholder="Ingrese dato de
alumno"><br><br>
<input type="submit" name="btnbuscar" value="Buscar">
<br><br>
<table >
<thead>
<th>Nombre:</th>
<th>Apellido 1:</th>
<th>Apellido 2:</th>
<th>Sexo:</th>
<th>Núm.Control</th>
</thead>
<tbody>
<?php
if(isset($_GET['btnbuscar'])){
$busqueda = $_GET['buscar'];
$consulta= $conectar -> query ("SELECT * from alumnos where nocontrol LIKE
'%$busqueda%' or nombre LIKE '%$busqueda%' or ape1 LIKE '%$busqueda%' or ape2 LIKE
'%$busqueda%' ");
while($row = $consulta -> fetch_array()){
?>
<tr>
<td><?php echo $row['nombre']; ?></td>
<td><?php echo $row['ape1'];?></td>
<td><?php echo $row['ape2'];?></td>
<td><?php echo $row['sexo'];?></td>
<td><?php echo $row['nocontrol'];?></td>
</tr>
<?php }
}
?>
</tbody>
</table>
</form>
</fieldset>
</body>
</html>

----------------
PHP Sentencias, métodos, funciones
mysqli --Es una extensión mejorada (i al final es de improved) de PHP, para acceder
a la base de datos MySQL.

mysql_query --Envia una única consulta, (no soporta multiples consultas) a la base
de datos actualmente activa, en el servidor asociado
con el identificador de enlace especificado por link_identifier

isset(). -- Determina si una variable esta definida y no es nula.

mysqli_fetch_assoc() --Funcion usada para regresar una representación asociativa de


la siguiente fila en el resultado, representado
por el parametro resultado, donde cada llave en la matriz representa el
nombre de la columna en el resultado.
Es una versión extendida de la función mysqli_fetch_row. Además de guardar la
información en los indices numericos del array resultante
la función tambien puede guardar la información en indices asociativos,
utilizando los nombres de los campos del resultado como claves.

function(){
}

? Signo de interrogación
El signo de interrogación es usado para devolver el tipo especificado o null, en
una función, en los valores de retorno para ser marcados como
anulables, al anteponer el prefijo nombre de tipo con un signo de interrogación (?)

También podría gustarte