Sensation Energy


F 7 & GRID Multi PHP Mysql

Documentation - Multi function

Union

Union is Join which is similar to INNER Join and also connects via ID. I have separated Crud and divided it into two parts where you can see how CRUD can function individually from the UNOION table. The Category and Product tables are shown to you above, and you will also see here how values are added to those tables.

Union table


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product Name</th>
<th>Category id</a></th>
<th>Category name</a></th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql = "SELECT * FROM categories JOIN products ON categories.cat_id=products.cat_id";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_id']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
<td>
<a href="p_cat.php?cat_id=<?php echo $row['cat_id']; ?>"><button class="btn-1">V.Cat.</button></a>
<a href="u_cat.php?cat_id=<?php echo $row['cat_id'];?>"><button class="btn-2">E.Cat.</button></a>
<a href="o_cat.php?cat_id=<?php echo $row['cat_id']; ?>" onClick="return confirm('Delete ?')\"><button class="btn-5">D.Cat.</button></a>
<a href="p_pro.php?product_id=<?php echo $row['product_id']; ?>"><button class="btn-6">V.Pro.</button></a>
<a href="u_pro.php?product_id=<?php echo $row['product_id']; ?>"><button class="btn-1">E.Pro.</button></a>
<a href="o_pro.php?product_id=<?php echo $row['product_id']; ?>" onClick="return confirm('Delete ?')\"><button class="btn-3">D.Pro.</button></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>

ADD, VIEW, EDIT, Delete Category and Product

ADD Category & Product

Add Category (add_ctegory.php)


<form action="" method="post">
<div class="form-group">
<label for="cat">Category Name</label>
<input type="text" name="cat_name" placeholder="cat name" class="form-input">
</div>
<br>
<div class="btn-group">
<button type="submit" name="ubaci" class="btn-3" >POST</button>
<input type="button" class="btn-2" onclick="location.href='index.php';" value="Cancel" />
</div>
</form>
<?php
require 'conn.php';
if(isset($_POST['ubaci'])){
$cat_name = $_POST['cat_name'];
$sql = "INSERT INTO categories (cat_name) VALUES ('{$cat_name}')";
if (mysqli_query($con, $sql)){
echo "<script>window.history.go(-2);</script>";
} else {
echo "Eror";
}
}
?>

Add Product (add_product.php)


<form action="" method="post">
<br>
<div class="form-group">
<label for="product">Product Name</label>
<input type="text" name="product_name" placeholder="product name" class="form-input">
</div>
<br>
<div class="form-group">
<label for="pk_id">Categoty</label>
<div>
<select name="cat_id" id="cat_id" class="form-input">
<?php
$query = "SELECT * FROM categories";
$select_categories = mysqli_query($con,$query);
while($row = mysqli_fetch_assoc($select_categories)){
$cat_id = $row['cat_id'];
$cat_name =  $row['cat_name'];
echo "<option value='$cat_id'>$cat_name</option>";
}
?>
</select>
</div>
</div>
<br>
<div class="btn-group">
<button type="submit" name="add"  >Add</button>
</div>
</form>
<?php
require 'conn.php';
if(isset($_POST['add'])){
$cat_id = $_POST['cat_id'];
$product_name = $_POST['product_name'];
$sql = "INSERT INTO products (product_name, cat_id) VALUES ('{$product_name}','{$cat_id}')";
if (mysqli_query($con, $sql)){
echo "<script>window.history.go(-2);</script>";
} else {
echo "Eror";
}
}
?>

Edit Category & Product

Edit Category (edit_ctegory.php)


<?php
require 'con.php';
$cat_id = $_GET['cat_id'];
$query = "SELECT * FROM categories WHERE  cat_id = $cat_id";
$select_posts = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($select_posts)) {
$cat_id = $row['cat_id'];
$cat_name= $row['cat_name'];
}
if (isset($_POST['edit'])) {
$cat_name =  $_POST['cat_name'];
$result = mysqli_query($con, "UPDATE categories SET cat_name='$cat_name' WHERE cat_id=$cat_id");
echo "<script>window.history.go(-2);</script>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="thread_title"><h2>Name</h2></label>
<input type="text" name="cat_name" class="form-input" value="<?php echo $cat_name; ?>">
</div>
<div class="btn-group">
<div align="center">
<input type="submit" name="edit" value="Edit">
</div>
</div>
</form>

Edit Product (edit_product.php)


<?php
require 'conn.php';
$product_id = $_GET['product_id'];
$query = "SELECT * FROM products WHERE  product_id = $product_id";
$select_posts = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($select_posts)) {
$product_id = $row['product_id'];
$product_name= $row['product_name'];
}
if (isset($_POST['edit'])) {
$product_name =  $_POST['product_name'];
$result = mysqli_query($con, "UPDATE products SET product_name='$product_name' WHERE product_id=$product_id");
echo "<script>window.history.go(-2);</script>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="thread_title"><h2>Name</h2></label>
<input type="text" name="product_name" class="form-input" value="<?php echo $product_name; ?>">
</div>
<div class="btn-group">
<div align="center">
<input type="submit" name="edit" value="Edit">
</div>
</div>
</form>

View Category & Product

View Category (view_ctegory.php)


<table>
<thead>
<tr>
<th>Category id</th>
<th>Category name</th>
</tr>
</thead>
<tbody>
<?php
require 'conn.php';
$cat_id=$_GET['cat_id'];
$up="SELECT * FROM categories WHERE cat_id='$cat_id'";
$pro = mysqli_query($con, $up);
while($row = mysqli_fetch_array($pro)){
?>
<tr>
<td><?php echo $row['cat_id']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

View Product (view_product.php)


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product name</th>
</tr>
</thead>
<tbody>
<?php
require 'conn.php';
$product_id=$_GET['product_id'];
$u="SELECT * FROM products WHERE product_id='$product_id'";
$procedural = mysqli_query($con, $u);
while($row = mysqli_fetch_array($procedural)){
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Delete Category & Product

Delete Category (delete_ctegory.php)


<?php
require 'conn.php';
$cat_id = $_GET['cat_id'];
$sql = "DELETE FROM categories WHERE cat_id=$cat_id";
$query = mysqli_query($con, $sql);
if ( $query) {
echo "<script>window.history.back();</script>";
}
?>

Delete Product (delete_product.php)


<?php
require 'conn.php';
$product_id = $_GET['product_id'];
$sql = "DELETE FROM products WHERE product_id=$product_id";
$query = mysqli_query($con, $sql);
if ( $query) {
echo "<script>window.history.back();</script>";
}
?>

Check & Radio button

Check button allows values to be checked. This means that if, for example, you have to select one or more values, you then check those values and press the button to enter in the database only those values that you checked.

Radio button similar to a checked button. It also allows the highlighted value to be inserted into the database. The difference is that with the checked button you can insert more values into the database, and with the Radio button only one value.

Check & Radio button

Check button (check.php)


<h2>Check button</h2>
<form method="post" action="cekirano.php">
<input type="checkbox" name="check[]" value="JS"><label>JS</label><br/>
<input type="checkbox" name="check[]" value="PHP"><label>PHP</label><br/>
<input type="checkbox" name="check[]" value="Mysql"><label>MySQL</label><br/>
<input type="submit" name="submit" Value="submit" class="btn-1">
<a href="o_c.php"  style='margin-left: auto;' class='link-unstyled' title='Make a change'> <i class='fa fa-trash'></i></a>
</form>
<br>
<?php
require 'conn.php';
$result = mysqli_query($con, "SELECT * FROM check_button ORDER BY id DESC");
?>
<table>
<tr>
<td>Id</td>
<td>Check</td>
</tr>
<?php
while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['id']."</td>";
echo "<td>".$res['check']."</td>";
}
?>
</table>

Radio button (radio.php)


<h2>Radio button</h2>
<form method="post" action="dugme.php">
<input type="radio" name="like" value="Website"><label>Website</label><br/>
<input type="radio" name="like" value="Mobile app"><label>Mobile app</label><br/>
<input type="radio" name="like" value="Web app"><label>Web app</label><br/>
<input type="submit" name="submit" Value="submit" class="btn-2">
<a href="o_d.php"  style='margin-left: auto;' class='link-unstyled' title='Make a change'><i class='fa fa-trash'></i></a>
</form>
<?php
require 'conn.php';
$result = mysqli_query($con, "SELECT * FROM radio_button ORDER BY id DESC");
?>
<table>
<tr>
<td>Id</td>
<td>Radio</td>
</tr>
<?php
while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['id']."</td>";
echo "<td>".$res['radio']."</td>";
}
?>
</table>

Select, Label, Check, Multi tag

Select, label and check is a table where I show you what the values entered in the multi insert look like. Multi insert is a form for unsos of various values such as a check button drop-down selection where you select values from a selection written in the label and a drop-down selection that pulls data from the database. The table below shows you all these inserted values. Searching allows you to search by date from the database or the name from the database also from the drop-down selection.

Select, label and check table and Add values

Select (index.php)


<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</a></th>
<th>Check</a></th>
<th>Role</th>
<th>Product</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
$sql1 = "SELECT * FROM users";
$result1 = mysqli_query($con, $sql1);
while($row1=mysqli_fetch_array($result1))
{
?>
<tr>
<td><?php echo $row1['id']; ?></td>
<td><?php echo $row1['name']; ?></td>
<td><?php echo $row1['email']; ?></td>
<td><?php echo $row1['check']; ?></td>
<td><?php echo $row1['role']; ?></td>
<td ><?php echo $row1['product']; ?></td>
<td><?php echo $row1['date']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>

Add (add.php)


<?php
require 'conn.php';
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Check</label>
<?php
$c = "SELECT * FROM check_button";
$b = mysqli_query($con,$c);
while($v=mysqli_fetch_assoc($b))
{
?>
<?php echo $v['check']; ?>
<input type="checkbox" class="form-input" name="cekirno[]" value="<?php echo $v['check']; ?>">
<?php } ?>
</div>
<div class="form-group">
<label for="name">Name</label>
<input id="name" type="text" class="form-input" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input id="email" type="text" class="form-input" name="email">
</div>
<div class="form-group">
<label for="role">Role</label>
<div>
<select name="role" id="role" class="form-input">
<option value='admin'>Admin</option>;
<option value='user'>User</option>;
<option value='moderator'>Moderator</option>;
</select>
</div>
</div>
<div class="form-group">
<label for="product">Product</label>
<div>
<select name="product" id="product" class="form-input">
<?php
$query2 = "SELECT * FROM products";
$select_categories = mysqli_query($con,$query2);
while($row2 = mysqli_fetch_assoc($select_categories)){
$product_id = $row2['product_id'];
$product_name =  $row2['product_name'];
echo "<option value='$product_name'>$product_name</option>";
}
?>
</select>
</div>
</div>
<div align="center">
<div class="btn-group">
<button type="submit" name="add" >Add</button>
</div>
</div>
</div>
</form>
<?php
if(isset($_POST['add']))
{
$today=date('d.m.Y');
$role = $_POST['role'];
$email = $_POST['email'];
$product = $_POST['product'];
$name=$_POST['name'];
$checkbox1=$_POST['check'];
$chk="";
foreach($checkbox1 as $chk1)
{
$chk .= $chk1.",";
}
$in_ch=mysqli_query($con,"insert into users(cekirno,name,date,product,role,email) values ('$chk','$name','$today','$product','$role','$email')");
if($in_ch==1)
{
echo'<script>alert("Inserted Successfully")</script>';
}
else
{
echo'<script>alert("Failed To Insert")</script>';
}
}
?>

Search from label and check

Search for date (search_date.php)


<?php
require 'conn.php';
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="date">Date</label>
<select name="date" id="date" class="form-input">
<?php
$query = "SELECT * FROM users group by date";
$select_categories = mysqli_query($con,$query);
while($row = mysqli_fetch_assoc($select_categories)){
$date =  $row['date'];
echo "<option value='$date'>$date</option>";
}
?>
</select>
</div>
<button type="submit" name="search">Search</button>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</a></th>
<th>Check</th>
<th>Role</th>
<th>Product</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['search'])) {
$date= $_POST['date'];
$c = "SELECT * FROM users where date='$date' ";
$b = mysqli_query($cona,$c);
while($v=mysqli_fetch_assoc($b))
{
?>
<tr>
<td><?php echo $v['id']; ?><br>
<td><?php echo $v['name']; ?><br>
<td><?php echo $v['email']; ?><br>
<td><?php echo $v['check']; ?><br>
<td><?php echo $v['role']; ?><br>
<td><?php echo $v['product']; ?><br>
<td><?php echo $v['date']; ?><br>
</tr>
<?php } }?>
</tbody>
</table>

Search for name (search_name.php)


<?php
require 'conn.php';
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Name</label>
<select name="name" id="name" class="form-input">
<?php
$query3 = "SELECT * FROM users";
$select = mysqli_query($con,$query3);
while($row3 = mysqli_fetch_assoc($select)){
$name =  $row3['name'];
echo "<option value='$name'>$name</option>";
}
?>
</select>
</div>
<button type="submit" name="search">Search</button>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</a></th>
<th>Check</th>
<th>Role</th>
<th>Product</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['search'])) {
$name= $_POST['name'];
$c = "SELECT * FROM users where name='$name' ";
$b = mysqli_query($con,$c);
while($v=mysqli_fetch_assoc($b))
{
?>
<tr>
<td><?php echo $v['id']; ?><br>
<td><?php echo $v['name']; ?><br>
<td><?php echo $v['email']; ?><br>
<td><?php echo $v['check']; ?><br>
<td><?php echo $v['role']; ?><br>
<td><?php echo $v['product']; ?><br>
<td><?php echo $v['date']; ?><br>
</tr>
<?php } }?>
</tbody>
</table>

Privilege & Role

Privilege & Role are lobsters for logging and skinning values ​​that the user can see if they are all values ​​or just some.

Here I have shown you that you can log in as an admin, user or moderator and depending on what role you have (admin, user or moderator.) You can see everything or what allows you to see.

The privileges here allow you to envy the chat assigned to you as a user in the CRUD you can see the following: All or only VIEW or only EDIT or Only DELETE. Of course with privileges you can combine for example someone can only see EDIT and DELETE or someone can see everything or someone can only see VIEW or someone can only see VIEW and EDIT, it all depends on what you want to set.

You can see a detailed overview of ROLE and Privileges with code at the following address:Privilege & Role


Content


Documentation


Answer the following question:

You must be logged in


Advertising