0% found this document useful (0 votes)
68 views

Laboratory Exercise 7 Bondoc

This document provides instructions for a laboratory exercise on creating a user form for a database using SQL statements in a programming language. Students are asked to build a user form with features like insert, delete, update and search functions. The form must be connected to a database, display data in a table, and include validation. Steps provided include starting Xampp, selecting a database, and creating the user form interface in a programming application like Visual Studio. The full syntax for the form is explained, showing how to insert, display, edit and delete data from the database through the graphical user interface.

Uploaded by

Rheny Bondoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Laboratory Exercise 7 Bondoc

This document provides instructions for a laboratory exercise on creating a user form for a database using SQL statements in a programming language. Students are asked to build a user form with features like insert, delete, update and search functions. The form must be connected to a database, display data in a table, and include validation. Steps provided include starting Xampp, selecting a database, and creating the user form interface in a programming application like Visual Studio. The full syntax for the form is explained, showing how to insert, display, edit and delete data from the database through the graphical user interface.

Uploaded by

Rheny Bondoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Ramon Magsaysay Memorial College

LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

LABORATORY EXERCISE 7
GUI: USER FORM (INSERT, DELETE, UPDATE, AND SEARCH/QUERY)

Learning Objectives
 To demonstrate the SQL statement in PL, such as Visual Studio / Java.
 To visualize and understand the role of the SQL statement in the Programming
Languages.
 To determine what SQL script used in implementing in User Form.

Prerequisite student experiences and knowledge


Database management has evolved from a specialized computer application to a central
component of a modern computing environment. As a result, knowledge about database
systems has become an essential part of computer science.

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. Then, open your program in Laboratory Exercise 6
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

6. Create a new form and name the form User_form


a. The form must have:
i. Three textboxes for (Name, username, and password)
ii. Button (insert, delete, edit, save, and exit)
iii. Search Textbox and button for display the query information
iv. Table for displaying the list of data from Database to GUI form.
b. Note: The form must have a validation.
7. Then build a syntax
8. Display the result.
9. Save and print the result on the page provided.
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

QUESTIONS

1. What parts of the process in developing the laboratory exercise 7 give you a problem?
Why?
- Honestly, I just used my CRUD activity in web system and technology subject. But in
my experience in making the CRUD activity, the part that gives me a problem was
the function that calls the data from the database to display it in the table and my
error was more on about the database connection.

2. Base on question number 1, how did you solve the problem?


- So I solved the problem by watching tutorials, mostly experiment and self-study.

3. Indicate the full syntax and explain it?


VIEWS
<?php $this->load->view('includes/header');?>

    <div class="container">

    <br>

    <br>

        <!-- Button trigger modal -->

        <button type="button" class="btn btn-primary" data-toggle="modal" data-


target="#exampleModal">

        INSERT

        </button>

    <br>

    <br>

        <!-- Modal -->

        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-


labelledby="exampleModalLabel" aria-hidden="true">

        <div class="modal-dialog" role="document">

            <div class="modal-content">
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

            <div class="modal-header">

                <h5 class="modal-title" id="exampleModalLabel">Add Data</h5>

                <button type="button" class="close" data-dismiss="modal" aria-label="Close">

                <span aria-hidden="true">&times;</span>

                </button>

            </div>

            <div class="modal-body">

                <form method="post" action="<?php echo site_url('User_controller/create')?>">

                    <div class="form-group">

                        <label for="exampleInputEmail1">Name</label>

                        <input type="text" class="form-control" name="name" aria-describedby="emailHelp"


placeholder="Enter Name" Required>

                    </div>

                    <div class="form-group">

                        <label for="exampleInputEmail1">Username</label>

                        <input type="text" class="form-control" name="username" aria-describedby="emailHelp"


placeholder="Enter User Name" Required>

                    </div>

                    <div class="form-group">

                        <label for="exampleInputEmail1">Password</label>

                        <input type="password" class="form-control" name="password" aria-


describedby="emailHelp" placeholder="Enter Password" Required>

                    </div>

                    <button type="submit" class="btn btn-primary" value="save">SAVE</button>

                </form>

            </div>
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

        </div>

    </div>

</div>

<table class="table">

    <thead class="table-success">

        <tr>

        <th scope="col">Name</th>

        <th scope="col">User Name</th>

        <th scope="col">Password</th>

        <th scope="col"></th>

    

        </tr>

    </thead>

    <tbody>

        <?php foreach($result as $row) {?>

        <tr>

        <th scope="row"><?php echo $row->name; ?></th>

        <td><?php echo $row->username; ?></td>

        <td><?php echo $row->password; ?> </td>

        <td> <button type="submit" class="btn btn-secondary"><a href="<?php echo


site_url('User_controller/edit');?>/<?php echo $row->User_ID;?>">Edit</a></button>  |

            <button type="submit" class="btn btn-danger"><a href="<?php echo


site_url('User_controller/delete');?>/<?php echo $row->User_ID;?>">Delete</a></button> </td>

        </tr>

        <?php } ?>
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

    </tbody>

</table>

</body>

</html>

<?php $this->load->view('includes/header');?>

    <div class="container">

    <br>

    <br>

        <form method="post" action="<?php echo site_url('User_controller/update')?>/<?php echo $row-


>User_ID; ?>">

            <div class="form-group">

                <label for="exampleInputEmail1">Name</label>

                <input type="text" class="form-control" name="name" value="<?php echo $row->name; ?>"


aria-describedby="emailHelp" placeholder="Enter Name">

            </div>

            <div class="form-group">

                <label for="exampleInputEmail1">User Name</label>

                <input type="text" class="form-control" name="username" value="<?php echo $row-


>username; ?>" aria-describedby="emailHelp" placeholder="Enter User Name">

            </div>

            <div class="form-group">

                <label for="exampleInputEmail1">Password</label>

                <input type="password" class="form-control" name="password" value="<?php echo $row-


>password; ?>" aria-describedby="emailHelp" placeholder="Enter Password">

            </div>
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

            <button type="submit" class="btn btn-primary" value="save">Save</button>

            <a href="<?php echo site_url('User_controller')?>"><button type="button" class="btn btn-


danger">EXIT</button></a>

        </form>  

        </div>

    </body>

</html>

<!doctype html>

<html lang="en">

  <head>

    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Optional JavaScript -->

    <!-- jQuery first, then Popper.js, then Bootstrap JS -->

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>

    <!-- Bootstrap CSS -->

    <link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">

    <title>USER FORM</title>

  </head>

  <body>

    <!-- As a link -->

    <nav class="navbar navbar-light bg-light">

    <a class="navbar-brand" href="#">USER FORM</a>

    <form class="form-inline my-2 my-lg-0">

      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">

      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>

    </form>

    </nav>

CONTROLLERS

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class User_controller extends CI_Controller {

    public function __construct() {

        parent:: __construct();

        $this->load->model('User_model');

  }

    /* gets the input data from the database and print */


Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

    public function index() {

        $data['result'] = $this->User_model->getAllData();

        $this->load->view('User_form', $data);

  }

        /* create array of data and insert to the database */

    public function create() {

        $this->User_model->createData();

        redirect("User_controller");

  }

        /* edit the specific row of data from the database */

    public function edit($User_ID) {

        $data['row'] = $this->User_model->getData($User_ID);

        $this->load->view('User_edit', $data);

  }

    /* updates the row of data from edit and print */

    public function update($User_ID) {

        $this->User_model->updateData($User_ID);

        redirect("User_controller");

  }

        /* delete the specific data  */

    public function delete($User_ID) {

        $this->User_model->deleteData($User_ID);

        redirect("User_controller");

  }

}
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

MODELS

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class User_model extends CI_Model {

    public function __construct() {

        $this->load->database();

  }

    /* create array of data and insert to the database */

    function createData() {

        $data = array (

            'User_ID' => $this->input->post('User_ID'),

            'name' => $this->input->post('name'),

            'username' => $this->input->post('username'),

            'password' => $this->input->post('password')

        );

        $this->db->insert('users', $data);

  }

    /* gets all the input data from the database and print */

    function getAllData() {

        $query = $this->db->query('SELECT * FROM users');

        return $query->result();

  }

    /* gets the specific data  */

    function getData($User_ID) {
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

        $query = $this->db->query('SELECT * FROM users WHERE `User_ID` =' .$User_ID);

        return $query->row();

  }

    /* updates the row of data from edit and print */

    function updateData($User_ID) {

        $data = array (

            'User_id' => $this->input->post('User_ID'),

            'name' => $this->input->post('name'),

            'username' => $this->input->post('username'),

            'password' => $this->input->post('password')

        );

        $this->db->where('User_ID', $User_ID);

        $this->db->update('users', $data);

  }

    /* delete the specific data  */

    function deleteData($User_ID) {

        $this->db->where('User_ID', $User_ID);

        $this->db->delete('users');

  }

}
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

Output / Results
Ramon Magsaysay Memorial College
LABORATORY EXERCISE
____ SEMESTER: AY: _________

Name: MARJUN C. PAGHID____ Schedule: WEDNESDAY-THURSDAY Score: ________


Subject: FUNDAMENTALS OF DATABASE SYSTEMS Instructor: _JIM JAMERO_____ Date: _11/09/22_

Conclusion

- Basically, this activity was similar to CRUD implementation. CRUD is the acronym of create,
read, update and delete. So, this activity has the insert, delete, edit, save, and exit and it
is very similar. This activity is about on how to integrate the database to the form
using php syntax.

You might also like