PHP – Simple Folder Generator

In this tutorial we will create a Simple Folder Generator using PHP. This code will generate a new folder when the user click the generate button. The code use a PHP POST method to call a specific function that will generate a new folder using mkdir() This is a user-friendly kind of program feel free to modify it.

We will be using PHP as a scripting language and interpreter that is used primarily on any webserver including xamp, wamp, etc. It is being use to any famous websites and it has a modern technology that can easily be use by the next generation.

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here’s the link for XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.

[blockquote align=”none” author=””]

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″ name=”viewport” content=”width=device-width, initial-scale=1″/>
<link rel=”stylesheet” type=”text/css” href=”css/bootstrap.css”/>
</head>
<body>
<nav class=”navbar navbar-default”>
<div class=”container-fluid”>
<a class=”navbar-brand” href=”<a href=”https://www.tecschool.com/”>tecschool.com</a>
“>https://www.tecschool.com/”>tecschool.com</a>
</a> </div>
</nav>
<div class=”col-md-3″></div>
<div class=”col-md-6 well”>
<h3 class=”text-primary”>PHP – Simple Folder Generator</h3>
<hr style=”border-top:1px dotted #ccc;”/>
<div class=”col-md-4″>
<form method=”POST” action=”generate.php”>
<div class=”form-group”>
<label>Enter a text</label>
<input type=”text” name=”folder” class=”form-control”>
</div>
<button class=”btn btn-primary” name=”generate”><span class=”glyphicon glyphicon-plus”></span> Generate</button>
</form>
</div>
<div class=”col-md-8″>
<table class=”table table-bordered”>
<thead class=”alert-info”>
<tr>
<th>Folder</th>
<th>Full Location</th>
</tr>
</thead>
<tbody>
<?php
$files = scandir(‘files/’);
foreach($files as $file){
if($file != “.” && $file != “..”){
?>
<tr>
<td><?php echo $file.”<br />”;?></td>
<td><?php echo realpath(‘files/’.$file) ?></td>
</tr>
<?php
}

}
?>

</tbody>
</table>
</div>
</div>
</body>
</html>

[/blockquote]

Creating the Main Function

This code contains the main function of the application. This code will generate a folder when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as generate.php

[blockquote align=”none” author=””]<?php
if(ISSET($_POST[‘generate’])){
$folder = $_POST[‘folder’];
if(!file_exists(‘files/’.$folder)){
mkdir(‘files/’.$folder);
echo “<script>alert(‘You created “.$folder.”!’)</script>”;
echo “<script>window.location=’index.php'</script>”;
}
}
?>[/blockquote]

There you have it we successfully created Simple Folder Generator using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Download Code Here

 

PHP – Auto Sum Total In SQLite3

In this tutorial we will create a Auto Sum Total In SQLite3 using PHP. This code will upload files to SQLite database when user click the upload button. This code will automatically calculate the total value exist in a table when user click the calculate button. The code use SQLite query to display and automatically calculate a value in the a table by adding SUM parameter in the selection query. This a free program, you can apply this to your system as your own.

We will be using SQLite that provides an interface for accessing the database. It includes class interfaces to the SQL commands. And also it allows you to create SQL functions and aggregate using PHP.

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here’s the link for XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Installing SQLite Browser
We will now then install the SQLite data viewer, here’s the link for the DB Browser for SQLite http://sqlitebrowser.org/.

Setting Up SQLite

First, we are going to enable SQLite 3 in our PHP.

  1. Open localhost server folder XAMPP, etc and locate php.ini.
  2. Open php.ini and enable sqlite3 by removing the semicolon in the line.

3.Save changes and Restart Server.

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.

[blockquote align=”none” author=””]

<?php
$conn=new SQLite3(‘db/db_product’) or die(“Unable to open database!”);
$query=”CREATE TABLE IF NOT EXISTS `product`(p_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, product_name TEXT, price TEXT)”;

$conn->exec($query);
?>

[/blockquote]

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.

[blockquote align=”none” author=””]

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ name=”viewport” content=”width=device-width, initial-scale=1″/>
<link rel=”stylesheet” type=”text/css” href=”css/bootstrap.css”/>
</head>
<body>
<nav class=”navbar navbar-default”>
<div class=”containr-fluid”>
<a class=”navbar-brand” href=”<a href=”https://tecschool.com”>tecschool</a>
” rel=”nofollow”>https://tecschool.com”>tecschool</a>
</a> </div>
</nav>
<div class=”col-md-3″></div>
<div class=”col-md-6 well”>
<h3 class=”text-primary”>PHP – Auto Sum Total In SQLite 3</h3>
<hr style=”border-top:1px dotted #ccc;”/>
<div class=”col-md-4″>
<form method=”POST” action=”save.php”>
<div class=”form-group”>
<label>Product</label>
<input type=”text” name=”product” class=”form-control” required=”required”/>
</div>
<div class=”form-group”>
<label>Price</label>
<input type=”number” min=”0″ name=”price” class=”form-control” required=”required”/>
</div>
<center><button class=”btn btn-primary” name=”add”>Add Product</button></center>
</form>
</div>
<div class=”col-md-8″>
<table class=”table table-bordered”>
<thead class=”alert-info”>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
require’conn.php’;
$query=$conn->query(“SELECT * FROM `product`”) or die(“Failed to fetch row!”);
while($fetch=$query->fetchArray()){

?>
<tr>
<td><?php echo $fetch[‘product_name’]?></td>
<td align=”right”><?php echo number_format($fetch[‘price’])?></td>
</tr>
<?php
}
?>
</tbody>
<?php include ‘autosum.php’?>
</table>
</div>
</div>
</body>
</html>

[/blockquote]

Creating the SQLite Query

This code contains the SQLite query of the application. This code will store the data inputs to SQLite database. To do this just copy and write these block of codes as shown below inside the text editor, then save it as save.php.

[blockquote align=”none” author=””]

<?php
require_once ‘conn.php’;

if(ISSET($_POST[‘add’])){
$product = $_POST[‘product’];
$price = $_POST[‘price’];

$query=”INSERT INTO `product` (product_name, price) VALUES(‘$product’, ‘$price’)”;

$conn->exec($query);

header(“location:index.php”);

}
?>

[/blockquote]

Creating the Main Function

This code contains the main function of the application. This code will auto calculate the value in the table when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor, then save it as autosum.php.

[blockquote align=”none” author=””]<tfoot>
<tr>
<td align=”right”>Total</td>
<td align=”right”>
<?php
if(!ISSET($_POST[‘sum’])){
?>
<form method=”POST” action=””>
<button class=”btn btn-success” name=”sum”>Calculate</button>
</form>
<?php
}else{
$query=$conn->query(“SELECT SUM(price) AS total FROM `product`”) or die(“Failed to fetch row!”);
$fetch=$query->fetchArray()
?>
<label class=”text-danger”><?php echo number_format($fetch[‘total’])?></label>
<?php
}
?>
</td>
</tr>
</tfoot>[/blockquote]

There you have it we successfully created a Auto Sum Total In SQLite3 using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

 

Download Code Here

 

PHP – Remove Table Row With Modal Using PDO

In this tutorial we will create a Remove Table Row With Modal using PDO. This code will launch a modal dialog when user click the remove button in the table The code use PDOquery to remove a specific data in the table row that needed some confirmation by a user to proceed to a necessary action. This a friendly-user kind of system, feel free to use and modify it

We will be using PDO as a query scripting it an acronym for PHP Data Objects. It is a lean, clean, and consistent way to access databases. This means developers can write portable code much easier.

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here’s the link for XAMPP server https://www.apachefriends.org/index.html

And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/

Creating Database

Open your database web server then create a database name in it db_pdo_delete_modal, after that click Import then locate the database file inside the folder of the application then click ok.

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.

[blockquote align=”none” author=””]<?php
$conn = new PDO( ‘mysql:host=localhost;dbname=db_pdo_delete_modal’, ‘root’, ”);
if(!$conn){
die(“Error: Failed to coonect to database!”);
}
?>[/blockquote]

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.

 

[blockquote align=”none” author=””]

<!DOCTYPE html>
<html lang=”en”>
<head>
<link rel=”stylesheet” type=”text/css” href=”css/bootstrap.css”>
<meta charset=”UTF-8″ name=”viewport” content=”width=device-width, initial-scale=1″/>
</head>
<body>
<nav class=”navbar navbar-default”>
<div class=”container-fluid”>
<a href=”<a href=”https://tecschool.com”” rel=”nofollow”>https://tecschool.com”</a> class=”navbar-brand”>tecschool</a>
</div>
</nav>
<div class=”col-md-3″></div>
<div class=”col-md-6 well”>
<h3 class=”text-primary”>PHP – Remove Table Row With Modal Using PDO</h3>
<hr style=”border-top:1px dotted #ccc;” />
<div class=”col-md-4″>
<form method=”POST” action=”insert.php”>
<div class=”form-group”>
<label>Firstname</label>
<input type=”text” name=”firstname” class=”form-control” required=”required”/>
</div>
<div class=”form-group”>
<label>Lastname</label>
<input type=”text” name=”lastname” class=”form-control” required=”required” />
</div>
<div class=”form-group”>
<label>Address</label>
<input type=”text” name=”address” class=”form-control” required=”required”/>
</div>
<center><button name=”save” class=”btn btn-primary”>Save</button></center>
</form>
</div>
<div class=”col-md-8″>
<table class=”table table-bordered”>
<thead class=”alert-info”>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
require ‘conn.php’;
$query = $conn->prepare(“SELECT * FROM `member`”);
$query->execute();
while($row = $query->fetch()){
?>
<tr>
<td><?php echo $row[‘firstname’]?></td>
<td><?php echo $row[‘lastname’]?></td>
<td><?php echo $row[‘address’]?></td>
<td><button class=”btn btn-danger” data-toggle=”modal” data-target=”#modal<?php echo $row[‘mem_id’]?>”><span class=”glyphicon glyphicon-trash”></span> Remove</button></td>
</tr>

<div class=”modal fade” id=”modal<?php echo $row[‘mem_id’]?>” aria-hidden=”true”>
<div class=”modal-dialog”>
<div class=”modal-content”>
<div class=”modal-header”>
<h3 class=”modal-title”>System Information</h3>
</div>
<div class=”modal-body”>
<center><h3 class=”text-danger”>Are you sure you want to remove this record?</h3></center>
</div>
<div class=”modal-footer”>
<a href=”remove.php?id=<?php echo $row[‘mem_id’]?>” class=”btn btn-danger”>Yes</a>
<button class=”btn btn-primary” type=”button” data-dismiss=”modal”>No</button>
</div>
</div>
</div>
</div>

<?php
}
?>
</tbody>
</table>
</div>
</div>
<script src=”js/jquery-3.2.1.min.js”></script>
<script src=”js/bootstrap.js”></script>
</body>
</html>

[/blockquote]

 

Creating the PDO Query

This code contains the PDO query of the application. This code will store the form inputs to the database server. To do this just kindly write these block of codes inside the text editor, then save it as insert.php.

[blockquote align=”none” author=””]require_once ‘conn.php’;

if(ISSET($_POST[‘save’])){

$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$address = $_POST[‘address’];

try{
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = “INSERT INTO `member`(firstname, lastname, address) VALUES (‘$firstname’, ‘$lastname’, ‘$address’)”;
$conn->exec($sql);
}catch(PDOException $e){
echo $e->getMessage();
}

$conn = null;

header(“location: index.php”);

}
?>[/blockquote]

Creating the Main Function

This code contains the main function of the application. This code will remove a table row when the button is clicked. To do this just kindly write these block of codes inside the text editor, then save it as remove.php.

[blockquote align=”none” author=””]

<?php
require_once ‘conn.php’;

if(ISSET($_REQUEST[‘id’])){
$query = $conn->prepare(“DELETE from `member` WHERE `mem_id`=’$_REQUEST[id]'”);
$query->execute();

echo “<script>alert(‘Successfully remove a row!’)</script>”;
echo “<script>window.location=’index.php'</script>”;

}
?>

 

[/blockquote]

There you have it we successfully created a Remove Table Row With Modal using PDO. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Download Code Here

 

 

Categorized in: