Código Aplicación
Código Aplicación
//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'];
//Buscar_Alumnos.php
<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
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 (?)