I'm practicing PHP and MySQLi y creating a class assistance system (Checking for students' assistance to a classroom). However, I seem to be stuck with a problem...
What I want to do is simple: Teachers enter a four-digit code they possess (saved in a database) to login. Their code is posted to the page uad_asist_class.php
and this page will perform a query in the database, showing the teacher's name for a simple greeting (all info in database).
EXAMPLE: Teacher enters code: 5690, page shows "Buenos dias, Pedro Romo"
The problem is neither $_GET
nor $_POST
are sending the code to the page (I checked the POST array and it's empty). I want to know what am I doing wrong. (Feel free to rip my code a new one, it's for a practice).
Here's the code:
index.php: This guy sends the code the teacher enters
<!DOCTYPE html>
<html>
<!--
Load the page to adapt to the viewport on any devices
-->
<meta
name = "viewport"
content = "width = device-width, initial-scale = 1.0">
<head>
<!--
Load script file
Loads the functions for this page
-->
<script
type = "text/javascript"
src = "../js/UAD-password-login.js?v=1.8">
</script>
<!--
Load the stylesheet
This stylesheet contains:
>> Buttons styling
>> Paragraphs and text styling
>> Custom formularies
-->
<link
rel = "stylesheet"
type = "text/css"
href = "../css/UAD-main-style.css?v=2.3">
<!--
Page title on Chrome, Firefox tabs
-->
<title>
Inicio de sesión
</title>
</head>
<!--
The page performs the function RealTimeClock
This function is defined on file "UAD-realtime-clock.js"
-->
<body onload = "RealTimeClock()">
<!--
Page main heading
-->
<center>
<!--
This heading shows the title of the page
This heading uses the style "uad_heading_01"
-->
<h1
id = "uad_heading_01"
align = "center"
style = "font-size:56px">
Inicio de sesión
</h1>
</center>
<center>
<!--
A subtitle, indicating the user what to do
-->
<p
class = "uad_text"
align = "center"
style = "font-size:24px">
Introduzca su clave de profesor para iniciar sesión...
</p>
</center>
<br>
<!--
Formulary inputs
-->
<form
action = "/uad_asist_class.php"
method = "post">
<!--
This class denotes a row, grouping divs in a horizontal line
-->
<div
class = "row">
<!--
This class denotes a column
A group of elements vertically aligned
-->
<div
class = "col"
align = "center">
<!--
Password bar
Password is captured here by the number buttons
-->
<input
id = "prof_password"
name = "clave"
class = "uad_password_input"
type = "text"
required
disabled = "disabled"
placeholder = "Clave..."
maxlength = "4">
<br><br>
<!--
Log In button
After inserting a password, log in with the teacher username
-->
<input
class = "uad_form_button"
type = "submit"
value = "I N I C I A R">
<!--
Eye button
Serves to show or hide the password
-->
<input
class = "uad_eyeicon_button"
onclick = "HideShowPassword()"
type = "button">
</div>
<br><br>
<!--
This class denotes a column
A group of elements vertically aligned
-->
<div
class = "col"
align = "center">
<!--
Number 1 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('1')"
value = "1">
<!--
Number 2 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('2')"
value = "2">
<!--
Number 3 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('3')"
value = "3">
<br>
<!--
Number 4 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('4')"
value = "4">
<!--
Number 5 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('5')"
value = "5">
<!--
Number 6 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('6')"
value = "6">
<br>
<!--
Number 7 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('7')"
value = "7">
<!--
Number 8 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('8')"
value = "8">
<!--
Number 9 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('9')"
value = "9">
<br>
<!--
Backspace button
-->
<input
class = "uad_del_button"
type = "button"
onclick = "ErasePassword()"
value = "<">
<!-- ← -->
<!--
Number 0 button
-->
<input
class = "uad_num_button"
type = "button"
onclick = "InsertPassword('0')"
value = "0">
<!--
Clear password input button
-->
<input
class = "uad_clear_button"
type = "button"
onclick = "ClearPassword()"
value = "C">
</div>
</div>
</form>
<br>
<!--
Real-time clock
Shows a real time clock on screen
-->
<div
class = "uad_text"
id = "realTimeClock"
align = "center"
style = "font-size:76px">
</div>
<br>
<!--
Real-time Date
Shows today's date in a format
-->
<div
class = "uad_text"
id = "todayDate"
align = "center"
style = "font-size:32px">
</div>
<!--
Footer of the page
Shows the information of the school, and the year of development
-->
<div
class = "uad_footer">
Universidad de Artes Digitales © 2018 - Guadalajara, Jalisco, México
</div>
</body>
</html>
uad_asist_class.php: This guy receives the code entered by the teacher, displaying info according to the input
<!--------------------------------------------------------------------------------------------------
uad_asist_class.html
This is the main page to capture students assistance in class.
Here, a teacher has logged in and starts capturing assistance by pressing buttons with the students' names. A buttons press adds a "NOT PRESENT" to that class block for the day, adding new absences after every class block.
Class blocks are intervals of 50 min for classes. There can be up to four blocks of that class per day, and only four blocks can exist weekly.
--------------------------------------------------------------------------------------------------->
<!DOCTYPE html>
<html>
<!--
Load the character set
-->
<meta
charset = "UTF-8">
<!--
Page head
-->
<head>
<!--
Load the JavaScript script
- Functions to show
-->
<script
type = "text/javascript"
src = "../js/UAD-capture-assistance.js?v=1.7">
</script>
<!--
Load this page's stylesheet
-->
<link
rel = "stylesheet"
type = "text/css"
href = "../css/UAD-assisthub-style.css?v=3.1">
<!--
Load the main stylesheet
-->
<link
rel = "stylesheet"
type = "text/css"
href = "../css/UAD-main-style.css?v=2.4">
<!--
Page title
Title for the tabs
-->
<title>
Toma de asistencias
</title>
</head>
<!--
Body of the page
-->
<body onload = "AssistMain()">
<div>
<!--
1st row:
-->
<div
class = "row">
<!--
1st column:
-->
<div
class = "col"
align = "center">
<!--
Display the university's logo
Check path "../Intranet_UAD/media/image/" for logo
-->
<img
src = "../media/image/uad_logo.png"
align = "center"
width = "413px"
height = "auto">
</div>
<!--
2nd column: WELCOME TO THE USER
Display a greeting message to the teacher.
Values change depending on the user who logged in
-->
<div
class = "col"
align = "center">
<!--
Display a simple greeting to the user
-->
<h1
id = "uad_heading_01"
align = "center"
style = "font-size:72px;">
¡Buen dia!
</h1>
<!--
Display the user's name
Value changes depending on logged user
-->
<p
class = "uad_text"
align = "center"
style = "font-size:44px;">
<?php
if(isset($_POST["clave"]))
{
echo "La clave insertada es: " . $_POST["clave"];
}
else
{
echo "Error!";
}
/*
$prof_clave = "";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "uad_personnel";
// Connection to database saved here
$connection = new mysqli($servername, $username, $password, $dbname);
//
if($connection->connect_errno)
{
//
die();
}
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$prof_clave = test_input($_POST['clave']);
}
function test_input($input)
{
$input = trim($input);
$input = stripslashes($input);
$input = htmlspecialchars($input);
return $input;
}
echo "La clave insertada es: " . $prof_clave;
$query = "SELECT nombre FROM profesores WHERE 'clave' LIKE '" . $prof_clave . "%'";
//
$result = $connection->query($query);
//
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
//
echo $row['nombre'] . "<br>";
}
}
else
{
//
echo "nombre no disponible";
}
//
$connection->close();
*/
?>
</p>
</div>
<!--
3rd column: CAREER LOGO
Show an image of the class' career.
Changes depending on the career the class belongs.
Values are:
- IDV : Ingenieria en Desarrollo de Videojuegos
- LDDA : Lic. en Diseño y Desarrollo de Aplicaciones
- LA : Lic. en Animación
- LPA : Lic. en Producción Audiovisual
Check path "../Intranet/media/image/" for the career logos
-->
<div
class = "col"
align = "center">
<!--
Display the university's logo
Check path "../Intranet_UAD/media/image/" for logo
-->
<img
src = "../media/image/idv_logo.png"
align = "center"
width = "auto"
height = "auto">
</div>
</div>
<!--
2nd row: INFO DISPLAY
- Class name. Info to display to teacher, changes depending on time.
- Date info. Display to user and used to insert data on ABSENCE table on database
- Student buttons. Click to set student as NOT PRESENT.
- Click again to unmark as NOT PRESENT.
-->
<div
class = "row">
<!--
1st column: CAPTURE ASSISTANCES
- Save the assistance data on the table.
-->
<div
class = "col"
align = "center">
<div
id = "ClockDisplay"
class = "uad_text"
align = "center"
style = "font-size: 48px;">
</div>
<br>
<div
id = "DateDisplay"
class = "uad_text"
align = "center"
style = "font-size: 24px"
>
</div>
</div>
<!--
2nd column: CAPTURE ASSISTANCES
- Save the assistance data on the table.
-->
<div
class = "col"
align = "center">
<div
class = "uad_text"
align = "center"
style = "font-size: 48px;">
Fundamentos de Fisica I
</div>
</div>
</div>
<br><br><br>
<?php
// Here we control the buttons to get the information to present the pages
// Here we will...
/*
1- Load a new
*/
?>
<!--
3rd row: INFO DISPLAY
- Class name. Info to display to teacher, changes depending on time.
- Date info. Display to user and used to insert data on ABSENCE table on database
- Student buttons. Click to set student as NOT PRESENT.
- Click again to unmark as NOT PRESENT.
-->
<div
class = "row">
<!--
1st column: CAPTURE ASSISTANCES
- Save the assistance data on the table.
-->
<div
class = "col"
align = "center">
<!--
1st column: CAPTURE ASSISTANCES
- Save the assistance data on the table.
-->
<input
class = "uad_long_button"
type = "button"
align = "center"
value = "Capturar">
</div>
</div>
</div>
<!--
Footer of the page
Shows the information of the school, and the year of development
-->
<div
class = "uad_footer">
Universidad de Artes Digitales © 2018 - Guadalajara, Jalisco, México
</div>
</body>
</html>
Also, i'm using XAMPP, phpmyadmin ver. 4.5.1 with default user and password information (Whatever else I need to check and wasn't added, please let me know)