Professional Documents
Culture Documents
LABORATORY EXERCISE
____ SEMESTER: AY: _________
Learning Objectives
To visualize and understand how to use SQL statement for user login.
To determine what SQL script use in implementing login or access form.
Background
SQL (Structured Query Language) is a nonprocedural language, and you specify what
you want, not how to get it. A block-structured format of English keywords uses in this Query
language. It has the following components. The SQL DDL (Data Definition Language) provides a
command for defining relation schemas, deleting relations, and modifying relation schema.
DML (Data Manipulation Language) includes commands to insert tuples into, delete tuples
from and modify tuples in the Database. Embedded and Dynamic SQL define how SQL
statements can embed within general-purpose programming languages, such as C, C++, JAVA,
COBOL, Pascal, and Fortran.
Materials/Resources
PC/Internet
Pen
Programming Application (Visual Studio, Netbeans)
MySQL (Xampp, Wampp & MySQL)
Web Browser (Internet Explorer, Mozilla, Google Chrome, Etc.)
Word-processing program
Laboratory Activity
Instructions: Perform the following steps.
1. Open the program Xampp
2. Click the Start for Apache and MySQL
3. Then, click MySQL Admin
4. Select Database, then click the Database created on laboratory exercise 1/2
5. Select the SQL menu, then
6. Type
CREATE TABLE Users (
User_ID int(15) primary,
9. Then build a syntax for the user can log in to the form
10. If the user login on the form, if the username and password inputted by the user
have existed in the table using the message will appear "Welcome!", hence incorrect
the message will appear "Username/Password Invalid."
11. Display the result.
12. Save and Print the result in the page provided.
2. What Error or problem did you encounter? And how did you resolve the issue?
- The error I encountered first is I forget to create a function to display the conditions
so when I got wrong input, there’s no indication of wrong username/password. The
solution I made was I just created a condition where if the input username or
password is correct so it will return true and redirect to the other link page and
display Welcome! Else, it will display username/password invalid.
echo form_close();
?>
</body>
</html>
Data.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Welcome!</h1> //displays welcome when the input data are matched to the
database or correct input data
<?php
echo "<pre>";
echo print_r($this->session->all_userdata());
echo "</pre>";
?>
</html>
{
$this->login();
}
{
$this->load->view('login_view');
}
{
{
$this->load->view('data');
} else {
redirect('sample/invalid');
}
}
{
$this->load->view('invalid');
}
{
$this->load->library('form_validation');
if ($this->form_validation->run())
{
$data = array(
'currently_logged_in' => 1
);
$this->session->set_userdata($data);
redirect('sample/data');
}
else {
$this->load->view('login_view');
}
}
{
$this->load->model('sample_model');
if ($this->sample_model->log_in_correctly())
{
} else {
return false;
}
}
{
$this->session->sess_destroy();
redirect('sample/login');
}
}
?>
Sample_model.php
<?php
/* Function to require set of data and save to the users table in database*/
{
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', $this->input->post('password'));
$query = $this->db->get('users');
if ($query->num_rows() == 1)
{
return true;
} else {
}
}
- We can possibly connect different database in a html login form type using different
techniques on how we call the database to connect the data and save/or get the
information to display. Database is important when we want to store various data and when
can use it for different purposes.