July 19 2014

Joomla prevent SQL injections in custom query

Tagged Under : , ,

Joomla
For custom query in Joomla is not prevent the SQL injections issue. So that, we need to add some script to the query.

In Joomla we can using $db->quote($param) to prevent SQL injections in custom query.

The Example of the query:
$db = JFactory::getDbo();
$query = "INSERT INTO table (`username`, `password`) VALUES (".$db->quote($username).", $db->quote($password))";
$db->setQuery($query);
$db->query();
In the query you not need to add Single Quote Symbol. Because it will help you add in your query.

June 04 2014

Adding number of days to Dates in MySQL

Tagged Under : ,

MySQL
One of my application need update the days when it have set the days inside the records. It was because sometimes user need extend the expired date to following number of days.

With the SQL statement it would be simple to complete the task.
UPDATE table 
SET expired_date = DATE_ADD(expired,INTERVAL 7 DAY) 
WHERE id = 1;
The above example only work on DATE or DATETIME field types. Remember it was day not days

June 04 2014

multiple counts with one SQL Query

Tagged Under : ,

MySQL
It have few ways to get multiple counts with one SQL Query. But, it also will return more then one row records to user, and also the total count wouldn’t appear if it no inside the records.

In the same time, user need did few times loop and if else conditions to get the results. It will slow down the application performance and give developer more job to completed the job.

In here, I have a better way to process multiple counts with one SQL Query and it just return one row record only.

Let’s see below example how the SQL look like:

April 20 2014

Javascript HTML select option display table

Tagged Under : ,

javascript
Normally HTML Select option only can display one column data only. But if we want display more then one column as below and how we can do it?
multiple option

The answer is, default HTML Select Option is cannot do it.

To built multiple column Select Option, we need use javascript and css to complete this advanced Select Option.

April 14 2014

Yii2 send email through swiftmailer expansion

Tagged Under :

Yii
In here i wouldn’t introduced what is swiftmailer, who interested can find the information by yourself. In below will explain how to send email with SMTP through Yii2 swiftmailer.

Inside the config folder. Open the web.php configuration file. You will see the following code as below:
$config = [
  ......
  'components' => [
    ......
    'mailer' => [
      'class' => 'yii\swiftmailer\Mailer',
      'useFileTransport' => true, //for the testing purpose, you need to enable this
    ]
  ]
]
If useFileTransport is enable, all the email wouldn’t send out and the email contents will keep a copy at ‘runtime/mail‘ folder.

April 08 2014

WordPress how to create or build a new simple plugin

Tagged Under :

Wordpress
To create a plugin is a single PHP file, but common practice put the files within a directory. To begin, create a folder and naming it as your plugin name. Then, create a main PHP file and naming the file with the name of your plugin:
my-first-plugin << Folder name
- my-first-plugin.php << main PHP file name

Now we need define the plugin so the WordPress will recognize it and allow it to be installed, removed, and activated. Open the main PHP file (my-first-plugin.php), and then add the following code to the top of the file:

March 29 2014

PHP how to insert Chinese character into MySQL

Tagged Under : ,

php
The way to insert Chinese character into MySQL table. You need set the table structure charset to utf8.
CREATE TABLE IF NOT EXISTS `contents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
After that, add the following code as below:
mysql_connect(HOST, USER, PASSWORD);
mysql_select_db(DBNAME);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER_SET_CLIENT=utf8");
mysql_query("SET CHARACTER_SET_RESULTS=utf8");

March 09 2014

ASP.net display MSSQL DateTime on razor.

Tagged Under : ,

asp.net
MSSQL store DateTime format is standard. But sometimes we need change the format to display it to user, let them more easy read and understand which Datetime format was set in our Application.

If use ASP.net retrieve the MSSQL DateTime Data to you application, it will display like below format.
asp.net

But, when validate the DateTime with ASP.net it will return an error.
asp.net

Because the DateTime format set in ASP.net was “06-03-2014 12:00:00 AM”. But now we just need to display Date only not need time.

March 04 2014

ASP.net summary of return Action Result type

Tagged Under :

asp.net
There are different type of results that are available in ASP.net MVC. When create new controller, they will come with actions by default. The Empty controller includes an Index action with a return value of type ActionResult. ActionResul class is the base class for all action results.

There are different ActionResult types explained below.

February 27 2014

ASP.net how to set model default value

Tagged Under : ,

asp.net
Because I want to show default value in my create page. and in the create page code was used Html.TextBox and model to generate the input box.

Since it was used model to generate the code and we also can use model to set the default value as well.

Below example code are showing how set the default value in model:
public class Category 
{
  public int ID { get; set; }
  public string Name { get; set; }
  public DateTime CreateDate { get; set; }
}