The most viewed posts

Registry Reviver

How to clean up Windows Computer

About Desktop Icons in Windows Computer

Driver Booster

CCleaner

some (JavaScript Array Method)

Myanmar font and keyboard for Windows

Advanced System Care

How to sell IT materials in zilastar.com

Web Development Services

The most viewed items

Desktop Hard Disk

Dell Inspiron 5559

HP ProBook 430

SONY Playstation Portable

Laptop RAM

External Hard Disk

Laptop

ZilaStar ICT Jun 20 2019, 18:43:43

Deleting a database

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$conn = mysqli_connect($server, $user, $password);
if($conn){
$query = "DROP DATABASE `TNW`";
$query_run = mysqli_query($conn, $query);
if($query_run){
echo 'Successfully deleted a Database.';
}else{
echo 'Deleting a database Error.';
}
}else{
echo 'Connection Error';
}
?>


ZilaStar ICT Jun 19 2019, 18:34:54

Creating a database

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$conn = mysqli_connect($server, $user, $password);
if($conn){
$query = "CREATE DATABASE `TNW`";
$query_run = mysqli_query($conn, $query);
if($query_run){
echo 'Successfully created a Database.';
}else{
echo 'Creating a database Error.';
}
}else{
echo 'Connection Error';
}
?>


ZilaStar ICT Jun 19 2019, 17:08:12

Connecting to database server in php

The following is the example of connecting to database server in php.

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$conn = mysqli_connect($server, $user, $password);
if($conn){
echo 'Successfull connected to the server.';
}else{
echo 'Connection Error.';
}
?>


ZilaStar ICT Jun 18 2019, 21:44:35

Codes for file upload in php (step4)

We can set the limitations in uploading files. For example, we allow to upload only jpg or jpeg images and the maximum file size is 800KB.

<?php
@$name = $_FILES['file']['name'];
@$type = $_FILES['file']['type'];
@$size = $_FILES['file']['size'];

@$extension = substr($name, strpos($name, '.')+1);
@$max_size = 800000;

@$tmp_name = $_FILES['file']['tmp_name'];
@$location = 'tnw87/';


if(isset($name) && !empty($name)){
if($extension == 'jpg' || $extension == 'jpeg'){
 if($size < $max_size){
 if(move_uploaded_file($tmp_name, $location.$name)){
  echo 'Successfully uploaded!';
 }else{
  echo 'Upload Errors!';
 }
 }else{
  echo 'The maximum file size is 800KB';
 }
}else{
 echo 'Only jpg or jpeg image is allowed!';
}
}else{
 echo 'Please choose a file to upload';
}

?>

<form action = "upload.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name="file"><br /><br />
<input type = "submit" value = "Submit">
</form>


ZilaStar ICT Jun 18 2019, 11:23:14

Codes for file upload in php (step3)

In this example, we will upload file to the designated location. So, we will create a folder to store the files we've uploaded and give name to that folder. I give it as tnw87. Ok, lets start write the following codes and discover how it works.

<?php
 $name = $_FILES['file']['name'];
 $type = $_FILES['file']['type'];
 $size = $_FILES['file']['size'];
 $tmp_name = $_FILES['file']['tmp_name'];
 if(@isset($name) && @!empty($name)){
 $location = 'tnw87/';

 if(move_uploaded_file($tmp_name, $location.$name)){
  echo $name. ' is successfully uploaded.';
 }else{
  echo 'Upload Errors';
 }
 }else{
  echo 'Please select file to upload';
 }
 ?>

 <style type = "text/css">
 form{margin-top : 100px; margin-left : 50px;}
 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">
 <input type = "file" name = "file"></br></br>
 <input type = "submit" value = "Upload">
 </form>


ZilaStar ICT Jun 17 2019, 16:57:06

Codes for file upload in php (step2)

When we upload a file into one location, the file is firstly saved in temporary location as a temp file. Ok, lets discover how it works. We will write the following codes and test it.

<?php
$name = $_FILES['file']['name'];
 $type = $_FILES['file']['type'];
 $size = $_FILES['file']['size'];
 $tmp_name = $_FILES['file']['tmp_name'];
 if(@isset($name) && @!empty($name)){
 $location = 'tnw87/';
 if(move_uploaded_file($tmp_name, $location.$name)){
  echo $name. ' is successfully uploaded.';
 }else{
  echo 'Upload Errors';
 }
 }else{
  echo 'Please select file to upload';
 }
 ?>

 <style type = "text/css">
 form{margin-top : 100px; margin-left : 50px;}
 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">
 <input type = "file" name = "file"></br></br>
 <input type = "submit" value = "Upload">
 </form>


ZilaStar ICT Jun 16 2019, 16:53:46

Codes for file upload in php (step1)

<?php
 @$name = $_FILES['file']['name'];
 @$type = $_FILES['file']['type'];
 @$size = $_FILES['file']['size'];
 if(@isset($name) && @!empty($name)){
  echo 'File name is <strong> '.$name.'</strong>, File type is <strong>'.$type.'</strong> nad File size is <strong> '.$size.'</strong>';
 }else{
  echo 'Please select file to upload';
 }
?>

 <style type = "text/css">
 form{margin-top : 100px; margin-left : 50px;}
 </style>

 <form action = "upload.php" method = "POST" enctype = "multipart/form-data">
 <input type = "file" name = "file"></br></br>
 <input type = "submit" value = "Upload">
 </form>


ZilaStar ICT Jun 15 2019, 16:56:35

Timestamp in php

<?php
$time = time();
$time_now = date('D M Y & H:i:s', $time);
$time_modified = date ('D M Y @ H:i:s', strtotime('+ 1 year') );
echo 'The current time is '.$time_now.'.</br>The time modified is '.$time_modified.'.'  ;
?>


ZilaStar ICT Jun 14 2019, 16:54:14

Using header in php

<?php
$redirect_page = 'https://www.tnw87.com';
$redirect = true;
if($redirect == true){
  header('location:' .$redirect_page);
}
?>


ZilaStar ICT Jun 14 2019, 13:09:33

Search and replace in php


<?php
$offset = 0;

if(isset($_POST['text']) && isset($_POST['search']) && isset($_POST['replace'])){
 $text = $_POST['text'];
 $search = $_POST['search'];
 $replace = $_POST['replace'];

 $search_length = strlen($search);
 
 if(!empty($text) && !empty($search) && !empty($replace)){
   while($strpos = strpos($text, $search, $offset)){
   $offset = $strpos + $search_length;
   $text = substr_replace($text, $replace, $strpos, $search_length);
   echo $text;
   }
 }else{
   echo 'Please fill all fields!';
 }
}
?>

<hr />
<form action="searchandreplace.php" method="POST">
<textarea name="text" rows="15" cols="60"></textarea><br /><br />
Search : </br>
<input type="text" name="search"><br /><br />
Replace : </br>
<input type="text" name="replace"><br /><br />
<input type="submit" value="Submit">
</form>


ZilaStar ICT Jun 13 2019, 13:07:01

Similarity in php

<?php
$string = 'Hi, this is the php testing!';
$string1 = 'Hi, this is string testing!';
similar_text($string, $string1, $result);
echo $result;
?>


ZilaStar ICT Jun 12 2019, 16:54:42

Wordcensoring in php

From the following example, you can learn the usage of form, textarea, isset, strtolower and str_replace. Every word 'love' you type in the text box, the codes will change with the word 'hate'.

<?php
$find = 'love';
$replace = 'hate';
if(isset($_POST['user_input']) && !empty($_POST['user_input'])){
   $user_input = strtolower($_POST['user_input']);
   $user_input_new = str_replace($find, $replace, $user_input);
   echo $user_input_new.'</br>';
}else{
  echo 'Please fill in the text box!';
}
?>

<form action = "wordcensoring.php" method = "POST">
<textarea name = "user_input" cols = "40" widths = "500"></textarea></br></br>
<input type = "submit" value = "Submit">
</form>


Page : 17 of 30
To Contact
Available Services
Terms and Conditions