MYSQL: Work with special characters

While programming with php, normally we works with mysql. And in mysql we insert, update, delete, fetch or compare string data.

But there are some special characters in a string which causes formatting level problems, values level problems and concatenation level problems while working with mysql.

And these special characters are: \x00 , \n , \r , \ , ‘ , ” , \x1a

For Example:
Our string is: Today is my friend’s birthday.

Here we want to insert this string in “description” field of “comments” table and compare it in select query.

So now we have to write queries using mysql_real_escape_string() to not cause any formatting, values or concatenation level problems and prevent database attack.

$query = "insert into comments (description) values ('" . mysql_real_escape_string("Today is my friend's birthday.") . "')";
$query = "select * from comments where description='" . mysql_real_escape_string("Today is my friend's birthday.") . "'";

Hope this will help you.

Extract files and directories from ZIP file in php

Some, Control Panel has no facility to extract files from the ZIP file. So that following script is useful to extract or unzip the zip file using php code.

Here, we have to provide the path from where zip file will be taking for extracting purpose and also provide the path where to put extracted files and directories (data).

See the Following script.

$zipObj = new ZipArchive();    // create zip object
$files = $zipObj->open(‘unzip/test.zip’); // Open Zip Archive
		
if ($files == TRUE)
{
	$zipObj->extractTo(‘extracted/’); // Unzip or Extract Zip file to given Directory.
	$zipObj->close();
}
Posted in PHP. 1 Comment »

How to remove an element from php array?

Before few days we have a requirement to remove an element from php array.

To fulfill our requirement we have used php functions.

There are three functions which can be useful to delete an element from php array.

“array_shift(array)” removes first element from an array.

“array_pop(array)” removes last element from an array.

“array_splice(array,start,length,array)” removes selected elements from an array and replaces it with new elements.

Follow the under given example to check it practically.

$array = array("first", "second", "third", "fourth", "fifth", "sixth");
array_shift($array);
array_pop($array);
array_splice($array, 0, 2);
print_r($array);

Hope this will help you.

Posted in PHP. 1 Comment »

How to Solve IE9 Problem of Opening link in New Tab/Window

Whenever i was trying to open any link in new window/tab, I was getting a blank idle tab. I was facing this problem for last few months but finally got solution which i wanted to share with you guys. I’ve tried these following solutions but none was able to solve it.

I’ve tried:

  • Tried using IE9 with “no add-ons” mode
  • Rolled back to ie8 & then re-install IE9 again
  • Reset default settings from Advanced Internet Options
  • Deleted temporary Internet files, cookies, history… etc.
  • Used “Microsoft fix it”
  • & also tried “cmd” file from Microsoft that solves such problems “ie8-rereg.32on64.

Solution:

Follow these methods:

Method 1:
Step 1: Boot into safe mode with networking and see if the issue persists.

See Advanced start-up options (including safe mode) for instructions on booting into safe mode with networking.

Note: Wireless connection may not work in safe mode with networking. I’d recommend you to use the wired internet connection in safe mode with networking.

Step 2: If the issue does not occur in safe mode, boot your system in a clean boot state (in normal mode) to troubleshoot the issue.

See How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

Note: After troubleshooting, ensure to set the computer to start as usual as mentioned in Step 7 in the above KB article.

Method 2:
Access the following link and refer to OnyXxL’s response posted on Wednesday, November 11, 2009 to fix the issue:

http://social.answers.microsoft.com/Forums/en-US/InternetExplorer/thread/e312e580-1cbc-496b-8c6b-b69b8535a7bb

How To Insert the Tween Shape In Flash?

“In the timeline window, select any frame from 2-24 with left-click. In the properties window you can now see an option to tween which is currently set to none and from choose Shape from the tween drop down selector.Now insert another KeyFrame at frame 26. Left Click any frame from 27-49 & then select the Shape Tween from the Properties window.

Be sure that you follow the instructions up to this point exaclty is you have a dotted line, rather than a solid line in your Timeline window.”

How to add New field in Virtuemart 2.0?

If you need an additional field for your own business requirement, you can do that by changing data model as well as some php code.
To add new field for product you have to make changes in php code of 3 or more separate files in the previous Virtuemart joomla 1.5 but in virtuemart 2.0 and joomla 1.7 version you only have to make change in only one file to add field.

Admin interface

To add field in virtuemart admin side, first you have to create field in your product table into database then you need to add field for product in virtuemart.
Follow this path from your site root
administrator\components\com_virtuemart\views\product\tmpl
File Name: product_edit_information.php for product
Add this type of code wherever you want to put new field.

<td width="21%" >[Your_Field_Name] </td>
<td >
<input type="text" class="inputbox" name="Your_Field_Name" value="<?php echo $this->product-> Your_Field_Name; ?>" size="32" maxlength="64" />
</td>

I hope this will help you.

Posted in Joomla. 3 Comments »

How to enable/disable the module in magento?

Some times magento new comers have no idea for “How to enable/disable the module in magento?”

So here is the guide for that.

The module/extension which we install or create in magento can be enable/disable from admin side.

Now to enable/disable the magento module, login to your magento admin.

Go to System -> Configuration from header menu.

Then click on “Advanced” option of “Advanced” tab from left column.

Here you can see the list of all installed or created magento modules/extensions. And you can enable/disable them by selecting appropriate value from combo.

Hope this will help you.

Posted in Magento. 1 Comment »

How to increase the History in Photoshop?

You may be already gone through that bad feeling of clicking “undo” many times but you have realized that Photoshop don’t provide you that many steps you need to get back but this problem can be easily solved by changin History States setting from “Edit > Preferences > Performance”menu.

There are many efficient ways of going back & forward in your projects like using the “Snapshots” feature, which are essentially confortable of your work that you can go back to. If you use Undo a lot and thinking of adding more History States then set it around ’30’ and be aware that adding too many History States on a single image will normally relsult in using so much RAM & if you have less than 2 GB of RAM then you should not use that Undo feature often!

Note: you can add upto 1000 History State levels in Photoshop

How To Get The New Google Bar

There are two way to get the New Google Bar:

1) For Google Chrome:

  1. Go get this extension to change cookies. http://bit.ly/rEmD2O
  2. Load Google.com and right-click to edit the cookies.
  3. Change “PREF” to this:
    ID=03fd476a699d6487:U=88e8716486ff1e5d:FF=0:LD=en:CR=2:TM=1322688084:LM=1322688085:S=McEsyvcXKMiVfGds
  4. Don’t forget to save your changes at the bottom.
  5. Reload and you have the new Google bar.

2) For other browsers:

  1. Launch http://www.google.com in Chrome, Firefox or Internet Explorer 8+.
  2. Open “Dev Mode” by pressing – if using Firefox : Ctrl+Shift+K(or F12), if Google Chrome : Ctrl+Shift+J(or F12), and If Internet Explorer : F12 and selecting the “console” tab.
  3. In the developer tools console paste :document.cookie=”PREF=ID=03fd476a699d6487:U=88e8716486ff1e5d: FF=0:LD=en:CR=2:TM=1322688084:LM=1322688085:S=McEsyvcXKMiVfGds; path=/; domain=.google.com”;window.location.reload();

    and hit enter.

  4. Reload Google website and enjoy the new layout, If you’re not in the US then replace “.google.com” with your domain in the code above (for example: “.google.co.uk” or “.google.co.in”).

If you’re successful you’re new Google Bar would be like this…Get New Google Bar

How to know ruby and rails version, and get list of local gems?

Just before three days we have requirement to know ruby and rails version, and get list of gems which have installed at our local environment.

To accomplish our requirement we have found following commands, and we have executed them in command prompt.


ruby –v
rails –v
gem list

Where, “ruby –v” displays information of installed ruby version, “rails –v” displays information of installed rails version and “gem list” displays list of installed gems with version.

Hope this will help you.