Please login to start chat

 
TNW (Web Service & ICT Solutions)
2021-06-08 19:35:29

Inserting data into table (eg.3)

Category : php tutorials

This step is a little bit more complex. In this step, we also check the User Id already exists or not. But, not too difficult. I hope you…

 
TNW (Web Service & ICT Solutions)
2021-06-08 18:00:27

Inserting data into table (eg.2)

Category : php tutorials

 This step is a litter bit complex. But, not too difficult. I hope you will be ok.

1. Create html form.

2. Connect to…

 
TNW (Web Service & ICT Solutions)
2021-06-08 09:30:40

Inserting data into table (eg.1)

Category : php tutorials

<?php
$server = 'localhost';
$username = 'root';
$password = ' ';
$db = 'TNW';
$conn = mysqli_connect($server, $username, $password, $db);
if($conn){
    $query = "INSERT INTO `username` VALUES(1, 'Thet', 'Naing',…

 
TNW (Web Service & ICT Solutions)
2020-10-22 19:13:57

Deleting table in a database

Category : php tutorials

<?php
$server = 'localhost';
$username = 'root';
$password = '';
$db = 'TNW';
$conn = mysqli_connect($server, $username, $password, $db);
if($conn){
$query = "DROP TABLE `username`";
$query_run = mysqli_query($conn, $query);…

 

Creating table in a database

Category : php tutorials

<?php
$server = 'localhost';
$username = 'root';
$password = '';
$db = 'TNW';
$conn = mysqli_connect($server, $username, $password, $db);
if($conn){
$query = "CREATE TABLE `username`(
UserId int(30) NOT NULL…

 

Connecting to a database

Category : php tutorials

<?php
$server = 'localhost';
$username = 'root';
$password = '';
$db = 'TNW';
$conn = mysqli_connect($server, $username, $password, $db);
if($conn){
echo 'Successfully connected to a database -' .$db. '.';…

 

Deleting a database

Category : php tutorials

<?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…

 

Creating a database

Category : php tutorials

<?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…

 

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

<?php
$server = 'localhost';
$user = 'root';
$password = '';
$conn = mysqli_connect($server, $user, $password);…

 

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

 

In this example, we will upload file to the designated location. So, we will create a folder to store the files we've uploaded…

 

When we upload a file into one location, the file is firstly saved in temporary location as a temp file. Ok, lets discover…

 

<?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>';…

 

Timestamp in php

Category : php tutorials

<?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…

 

Using header in php

Category : php tutorials

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

 

Search and replace in php

Category : php tutorials


<?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 =…

 

Similarity in php

Category : php tutorials

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

 

Wordcensoring in php

Category : php tutorials

From the following example, you can learn the usage of form, textarea, isset, strtolower and str_replace. Every word 'love' you type in the…

 

Array in php

Category : php tutorials

 Normally There are three types of array: Indexed Array, Associative Array and Multi-Dimentional Array.

1. Indexed Array (Works with number)…

 

Matching with function in php

Category : php tutorials


<?php
$string = 'I am Thet Naing Win and who are you?';
$find = '/000/';

function Match($find, $string){
  if(preg_match($find, $string)){
   return true;
  }else{
   return false;
  }
}

if(Match($find,…

 

Matching in php

Category : php tutorials

<?php
$string = 'Hi How are you?. I am Thet Naing Win. Nice to meet you!';
$find = '/000/';
if (preg_match($find, $string)){
  echo 'Match Found!';
}else{
  echo 'Match Not…

 

Randomization in php

Category : php tutorials

<?php
if(isset($_POST['roll'])){
 $rand = rand(000, 999);
 echo 'You rolled a '.$rand.'.';
}
?>

<form action = "rand.php" method = "POST">
<input type = "submit" name = "roll" value =…

 

Using html form in php

Category : php tutorials

<?php
 if(isset($_POST["username"]) && isset($_POST["password"])){
  $username = $_POST["username"];
  $password = $_POST["password"];

  if(!empty($username) && !empty($password)){
   echo 'Welcome to TNW, '.$username.'!';
  }else{
   echo 'Fill in all fields!';
  }
 }
?>

<form action…

 

Function with return value in php

Category : php tutorials

<?php
function Add($num1, $num2){
$result = $num1 + $num2;
return $result;
}

function Divide($num1, $num2){
  $result = $num1/$num2;
  return $result;
}
$info = Add(Add(5,5), Divide(4,2));
echo $info;
?>

 

Function in php

Category : php tutorials

<?php
function MyName(){
echo 'Thet Naing Win.';
}
echo 'My Name is ';
MyName();
?>

 

Do while loop in php

Category : php tutorials

<?php
$count = 1;
$message = 'Hello!';
do {
  echo $count.'. '.$message.'</br>';
  $count ++;
}
while($count<=10)
?>

 

While loop in php

Category : php tutorials

<?php
$text = 'I am Thet Naing Win.';
$count = 1;
while($count <= 10){
  echo $count. ' '.$text.'!</br>';
  $count ++;
}
?>

 

For loop in php

Category : php tutorials

<?php
$text = 'I am Thet Naing Win.';
for($count = 1; $count <= 10; $count++){
echo $count. ' '.$text. '!</br>';
}
?>

 

For each statement in php

Category : php tutorials

<?php
 $food = array('Healthy'=>array('Salad', 'Milk', 'Coconet', 'Ground_nut'),

              'Unhealthy'=>array('Alcohol', 'Beer', 'Ice_cream'));

foreach($food as $element => $inner_element){
  echo '</br><strong>'.$element.'</strong></br>';

foreach($inner_element as $item){
  echo $item.'</br>';
}
}
?>

 

Switch statement in php

Category : php tutorials

$date = 'Sunday';

switch($date){
case 'Saturday';
case 'Sunday';
echo 'It is weekend!';
break;

default;
echo 'It is not weekend day!';
break;
}
?>

 

If statement in php

Category : php tutorials

<?php
$num1 = 30;
$num2 = 40;
if($num1 > $num2){
  echo 'Num1 is greater than Num2!';
} else if($num1 == $num2){
  echo 'Num1 and Num2 are equal!';
}else{
  echo…

 

String replace in php

Category : php tutorials

<?php
$string = 'I am thet naing win';
$find = array('thet', 'naing', 'win');
$replace = array('THET', 'NAING', 'WIN');
$string_new = str_replace($find, $replace, $string);
echo $string_new;
?>

 

String position in php

Category : php tutorials

<?php
$string = 'I am Thet Naing Win. This is PHP Testing and Word position Test. If you are insterested in PHP, please join us!';
$find = 'T';
$find_length…

 

String lower and upper in php

Category : php tutorials

We can change all characters to lower case by using strtolower. The following code is an example.

<?php
$string = 'I am…

 

String trim in php

Category : php tutorials

<?php
$string = 'I am Thet Naing Win.';
$string_trimmed = rtrim($string);
echo $string_trimmed;
?>

 

String reverse in php

Category : php tutorials

<?php
$string = 'I am Thet Naing Win';
$string_reversed = strrev($string);
echo $string_reversed;
?>

 

String word count in php

Category : php tutorials

<?php
$string = 'I am Thet Naing Win and who are you?';
$string_word_count = str_word_count($string, 1);
print_r($string_word_count);
?>

 

String length in php

Category : php tutorials

<?php
$string = 'I am Thet Naing Win';
$strlen = strlen($string);
echo $strlen;
?>

 

Checking php version by Code

Category : php tutorials

Write the following code and save it as info.php in C > xampp > htdoc.

 

Creating first php file in Windows

Category : php tutorials

We need Apache Service to run php codes. Now I hope you've already installed the Apache Service in your Windows PC. If you…

 

We need Apache service to run php codes. Xampp is the open source software we can use as Apache Server in Windows. Please…

 

Creating first php file in Ubuntu

Category : php tutorials

We need Apache Service to run php codes. Now, I hope you've already installed Apache Service in your Ubuntu PC. If you have…

 

Installing php 7.0 in Ubuntu

Category : php tutorials

Installing php 7.0

sudo apt-get install php7.0

To search php extensions

apt-cache search php7.*

Then, you can install php extensions upon the services you need.