TUTORIAL || HOW TO MAKE CRUD WITH PHP MYSQL USING DELETE DATA METHOD Part #4

in #utopian-io6 years ago (edited)

What Will I Learn?

  • We will learn how to make crud
  • We will learn how to delete data by using crud method
  • We will learn how to work from crud using method of data deletion

Requirements

  • Xampp
  • Text editor
  • The browser application

Difficulty

  • Intermediate

Tutorial Contents

C (Create): which means to create a new data, for example we are doing the registration disebuah web that already constitute Create from CRUD because we make and save registration data to database.

R (Read): Read or display a data that was located in MySQL database for example, then displayed in WEB using Php

U programming language (Update): well for this one process is editing a data from database which then edited using Php programming language in the form of WEB. Example edit facebook profile.

D (Delete): Surely you know what function is not it? Its function is almost the same as Update but this process is to do the deletion of data in the database through Php language. Examples on a blog sometimes have comments, then we delete the comment, well it includes the delete process in CRUD.

CRUD is often used in data processing applications that most mengguanakan CRUD functions therein. This function is used to add data, delete data, and update data.
Previously I've made a tutorial crud by mengunakakn php dengen various methods is terahrih method in the use of crud is delete.

delete data is a way or process to dispose of user data that is not in want

Getting Started
  • Create a data base with the name "crud".

1.png

  • Kemuadian create table with "user"

2.png

  • And then create 4 colom in User Table (id, name, address, job)

3.png

  • then create the main index.php file

index.php

"
< !DOCTYPE html>

< html>

< head>

< title>How To Make CRUD With PHP And MySQL - Displays data from database</title>

< link rel="stylesheet" type="text/css" href="style.css">

< /head>

< body>

< div class="judul">        
    < h1>Make CRUD With PHP And MySQL</h1>

    < h2>Displays data from database</h2>
    
</div>
<br/>

<?php 
if(isset($_GET['pesan'])){
    $pesan = $_GET['pesan'];
    if($pesan == "input"){
        echo "Data berhasil di input.";
    }else if($pesan == "update"){
        echo "Data berhasil di update.";
    }else if($pesan == "hapus"){
        echo "Data berhasil di hapus.";
    }
}
?>
<br/>
<a class="tombol" href="input.php">+ Tambah Data Baru</a>

<h3>Data user</h3>
<table border="1" class="table">
    <tr>
        <th>No</th>
        <th>Nama</th>
        <th>Alamat</th>
        <th>Pekerjaan</th>
        <th>Opsi</th>       
    </tr>
    <?php 
    include "koneksi.php";
    $query_mysql = mysql_query("SELECT * FROM user")or die(mysql_error());
    $nomor = 1;
    while($data = mysql_fetch_array($query_mysql)){
    ?>
    <tr>
        <td><?php echo $nomor++; ?></td>
        <td><?php echo $data['nama']; ?></td>
        <td><?php echo $data['alamat']; ?></td>
        <td><?php echo $data['pekerjaan']; ?></td>
        <td>
            <a class="edit" href="edit.php?id=<?php echo $data['id']; ?>">Edit</a> |
            <a class="hapus" href="hapus.php?id=<?php echo $data['id']; ?>">Hapus</a>                   
        </td>
    < /tr>
    < ?php } ?>
< /table>

< /body>
< /html>
"

  • after that create an index.php connection with the database.

"

<?php

$host = mysql_connect("localhost","root","");

$db = mysql_select_db("crud");

?>
"

  • Next we create the delete.php file to delete the data in the database.

"

<?php

include 'koneksi.php';

$id = $_GET['id'];

mysql_query("DELETE FROM user WHERE id='$id'")or die(mysql_error());

header("location:index.php?pesan=hapus");
?>

"

Program Explanation
  • In the above sytax contained in the file delete.php here we still memperluka database then connect first file delete.php with connection.php

"
include 'koneksi.php';
"

  • Then to get the data id and put it into one variable. and which is taken adlah data id that will want to delete.

"
$id = $_GET['id'];
"

  • Then we delete the data in the user table that contains the corresponding id in the send.

"
mysql_query("DELETE FROM user WHERE id='$id'")or die(mysql_error());
"

  • And we delete the command with mysql DELETE FROM user WHERE id = '$ id' and finally we switch the page back to index.php after the data is deleted.

"
header("location:index.php?pesan=hapus");
"

  • And to beautify the look we add a bit of CSS to all from that on this crud.

style.css

"
body{
font-family: 'roboto';
color: #000;
}

.judul{
background: #42A5F5;
padding: 10px;
text-align: center;

}

.judul h1,h2,h3{
height: 15px;
}

a{
/color: #fff;/
padding: 5px;
text-decoration: none;
}

.table{
border-collapse: collapse;
}

table.table th th , table.table tr td{
padding: 10px 20px ;
}
"

  • now we run the application and will look like this

1.png

  • after the run click the hapus button

2.png

  • and it will look like this

3.png

and tutorial how to make crud by using method delete data finish

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Plagiarised from here.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.26
TRX 0.13
JST 0.032
BTC 60837.81
ETH 2874.77
USDT 1.00
SBD 3.62