Social Icons

Wednesday, July 17, 2013

How to make a free website

A very common question, how to make a website. Here, I am going to explain this in detail.

Most of the people want to create their own website. Specially they want it for free completely means they want to create a website for completely free of cost. So, how to make a free website???. Well, a website is of two types: Static websites and dynamic websites. A static website is that which content is fixed for all users while dynamic website's content differ from user to user for example: your home page content of facebook is different from your friend.

A website can be designed in two ways: either using website builder (or something like cms) or with programming. In this part, I will explain how to create a free website without having knowledge of programming. In the later part, I will discuss to create website with programming and publish it. So, if you don't know programming and want to create a website for free, then this part is for you. Here we go.

You can create website with site builders. There are so many site builders available on internet. They are: weebly (www.weebly.com), wix (www.wix.com), google sites (sites.google.com) etc. They all have features like having a lot of templates, drag and drop features for paragraph, title, images etc. With the free edition, they may provide you lesser facilities. By upgrading your account on some payment, you will get more features there. That you can decide after checking out the features there and as per your needs. Also, you will get one click publish there which will publish your website on internet and anyone can see it.

Do registration in any of the above mentioned websites and there you will get option to create a free website. You will type name for your website like what you want to keep name of your website (for example www.prembaranwal.com) But you will get an option to have your website name as a sub-domain name only. For example, if you are creating your website through weebly, then your website will be like this www.yourwebsite.weebly.com like that. These site builders have some pattern for your website link(url) generation. If you want to make it with your domain name only (like www.yourwebsite.com) then you have to pay for it and upgrade your account. In that case, they will set up your account with your desired domain name and your website will open with www.yourwebsite.com A website always looks more professional with your own website domain name. But if you don't want to pay anything then also its ok. You can publish your website with subdomain as I mentioned above and anyone in the world can see it.

In the next tutorial, I will explain: If you know programming and have made the website in your local and want to publish on the web (internet) for free or at a minimal charge

Monday, June 24, 2013

Check mysql engine for a specific table

In MySql, there are many storage engines like MyISAM, InnoDB etc. What if you want to check the type of storage engine for a specific table as what storage engine it is using. You can check it as follows:

Run the below query:

SHOW TABLE STATUS WHERE Name='your_table_name'

The above query will give you the storage engine name with some more additional data, your table uses.

Similarly, if you want to check storage engines for all tables in your mysql database at once, then simply run this query:

SHOW TABLE STATUS

It will give you details about the storage engines for all the tables in your mysql database.

Wednesday, June 19, 2013

PHP file upload

In a website, it is a common requirement to upload a file or photo (image). Here, I am providing a solution as how can do it in PHP. It is not advisable to store the file in database directly. Instead, you should store the file in your project folder and in your database, you should store only the path of the file. So, we'll follow the same approach only.

First we design a form containing a file field. HTML code for the form containing a file field is :

<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
File: <input type="file" name="myfile" id="myfile"/>
<br/>
<input type="submit" name="submit" id="submit" value="Upload File"/>
</form>
</body>
</html>

Above is just the html code for displaying a file field in the web page. Now, on clicking  of submit button, it will redirect you to upload.php as it is defined in form action. So, we'll write the code for upload.php now.

upload.php

<?php

if ( $_FILES['myfile']['error'] > 0)
{
  echo "Error: ".$_FILES['myfile']['error'];
}
else
{
  if (file_exists("upload/" . $_FILES["myfile"]["name"]))          //upload/file is the path where file                                                                                                                 gets stored
  {
      echo $_FILES["myfile"]["name"] . " already exists. ";
  }
  else
  {
      move_uploaded_file($_FILES["myfile"]["tmp_name"],
      "upload/" . $_FILES["myfile"]["name"]);
      echo "File Stored in: " . "upload/" . $_FILES["myfile"]["name"];
   }}
?>


Thats it. Now, your file upload script is ready. In the above code, "upload/" . $_FILES["myfile"]["name"] is the path where file gets uploaded or stored.  Make sure, you have 'upload' directory in your project folder path. Now as your file gets stored, if you want to save its path in database, then you can run a sql query in your upload.php script as its path after uploading the file. In that case, anytime you can echo the file with the help of the path.

Thursday, June 6, 2013

Find 2nd highest or nth highest salary of employee in sql

It is one of the common questions for developers and also asked in interviews frequently to find 2nd highest salary or nth highest salary of an employee from the employee table. Here, I am providing solution for both.

To find 2nd highest (or maximum) salary of employee, you can write your query like this in MySql:

Select max(salary) as salary 
From employees 
Where salary<(Select max(salary) From employees);

The above sql query will give you the 2nd highest salary of employee. Here, 'employees' is the name of the table in the database.

But, what if you have to find 3rd highest or 4th highest or nth highest salary of employee. If you will follow the above approach then you will have to write the subquery for n times. That doesn't seem good. Here, I am providing a generalized solution to find nth highest salary.  Look at the below sql query:


SELECT DISTINCT(salary) 
FROM employees 
ORDER BY salary DESC LIMIT (n-1) , 1


Here, n is the highest term for which you have to find out highest salary. The above query will give you nth highest salary.

Tuesday, June 4, 2013

Difference between single quote and double quote in PHP

In PHP, if yu have to display or echo something (say a string), then you can do it with the help of single quote and double quote both. But there is a little difference between them as :

A single quoted string doesn't have variables within it interpreted but a double quoted string does. It can be better understood with the following example:

<?php
$a = 'prem';
echo 'My name is $a';
echo "My name is $a";
?>

For the first echo statement having single quote, output will be
My name is $a

For the second echo statement having double quoted string, output will be
My name is prem

So, if you have to define a constant string then better use with single quote and if you have variable too in the string then go with double quotes.

Thursday, May 30, 2013

Installing and Setup Yii framework - PHP

Yii framework is one of the popular PHP MVC framework these days. Here, I am providing a guide to install yii framework. Just make sure your web server is capable of supporting PHP 5.1 orr higher. I assume that you have already installed web server and PHP or softwares like wamp, xampp or lamp. So, here we go.

First, download the yii framework from http://www.yiiframework.com/download/ . Unpack the downloaded file to a web accessible folder. For example, if you have xampp installed then place it inside xampp/htdocs/ , if wamp then you can place it in wamp/www/ . Now, you can check if your server satisfies all requirements for using yii and the installation was a success. I assume you have installed xampp server and put the downloaded yii folder inside xampp/htdocs/ . Now, open the url in your browser as http://localhost/yii/requirements/index.php You will see the results there. Few fields may show warnings like for PDOSQLite extension or memcache extension. But that is ok. You can proceed. Now, lets talk about creating a new application in yii.

Creating a new application in yii

We will use a command line tool 'yiic' that comes packaged with he yii framework. It is not mandatory to use this toll but it saves time and helps in creating a new yii application easily. Now, open your command terminal and change to your webroot folder i.e, till xampp/htdocs.

cd xampp/htdocs

If you have installed wamp then you have to reach to wamp/www. Here, I assumed you have xampp installed.

Now, as you put yii downloaded folder inside htdocs as xampp/htdocs/yii, run the command like this...

yii/framework/yiic webapp demo

Here, 'demo' is your project folder name.

Note: If you get the error here as : php.exe is not recognized as an internal or external command then look here for the solution: http://awesomesirjee.blogspot.in/2013/05/phpexe-is-not-recognized-as-internal-or.html

On running the above command, it will give you message as :

Create a Web application under '/xampp/htdocs/demo'? [Yes|No]
Yes

It will create you application successfully. You can check a new folder named 'demo' is there in xampp/htdocs/ . You see how easily you created a new brand yii application with just one command. Now, got your browser and type in url: http://localhost/demo/index.php

You will find your new application running with a welcome page. Thats it.

php.exe is not recognized as an internal or external command - yiic - yii framework

This is a common error that you can come across while creating a new yii application using 'yiic' command tool. If you get this error, follow the below steps and your error will be fixed.

You just need to add complete path of your php.exe in yii/framework/yiic.bat
yiic.bat is the MS-DOS batch file.
For example in my case, it will be

if "%PHP_COMMAND%" == "" set PHP_COMMAND=C:\xampp\php\php.exe

This solution will work only for yii.

If you want to make it for all i.e make it possible to run php.exe in any command line instance, then you will have to add path of php.exe in your PATH environment variables.

Total Pageviews