Reset the password in drupal 7

If you forgot the password of your drupal admin then dont worry,

just follow some steps given here:

add following code in root index.php file on the top

define(‘DRUPAL_ROOT’, getcwd());
require_once DRUPAL_ROOT . ‘/includes/’;
require_once ‘includes/’;
echo user_hash_password(‘your-new-password’); die();

now copy this password and update in your database.

Have a fun


Validate image with dimension


<input type=”file” required=”required” class=”file” id=”category_image” error=”error” name=”category_image”>


errorElement: ‘div’,
errorClass: ‘help-block’,
focusInvalid: false,
rules: {
“category_image”: {
extension: “png|jpg|gif|jpeg|bmp”
messages: {
“category_image”: {
extension: “This field can accept images only!”
invalidHandler: function (event, validator) { //display error alert on form submit
$(‘.alert-danger’, $(‘.login-form’)).show();

highlight: function (e) {

success: function (e) {

errorPlacement: function (error, element) {
if(‘:checkbox’) ||‘:radio’)) {
var controls = element.closest(‘div[class*=”col-“]’);
if(controls.find(‘:checkbox,:radio’).length > 1) controls.append(error);
else error.insertAfter(element.nextAll(‘.lbl:eq(0)’).eq(0));
else if(‘.select2’)) {
else if(‘.chosen-select’)) {
else error.insertAfter(element.parent());
var _URL = window.URL || window.webkitURL;
$(‘.file’).on(‘change’, function() {
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
alert(“Width:” + this.width + ”   Height: ” + this.height);
img.src = _URL.createObjectURL(file);

Hour dropdown

<select id='time'>
<?php for($i = 1; $i <= 24; $i++): ?>
    <option value="<?= $i; ?>"><?= date("h.iA", strtotime("$i:00")); ?></option>
<?php endfor; ?>
<select id='time'>
    <option value="1">01.00AM</option>
    <option value="2">02.00AM</option>
    <option value="3">03.00AM</option>
    <option value="4">04.00AM</option>
    <option value="5">05.00AM</option>
    <option value="6">06.00AM</option>
    <option value="7">07.00AM</option>
    <option value="8">08.00AM</option>
    <option value="9">09.00AM</option>
    <option value="10">10.00AM</option>
    <option value="11">11.00AM</option>
    <option value="12">12.00PM</option>
    <option value="13">01.00PM</option>
    <option value="14">02.00PM</option>
    <option value="15">03.00PM</option>
    <option value="16">04.00PM</option>
    <option value="17">05.00PM</option>
    <option value="18">06.00PM</option>
    <option value="19">07.00PM</option>
    <option value="20">08.00PM</option>
    <option value="21">09.00PM</option>
    <option value="22">10.00PM</option>
    <option value="23">11.00PM</option>
    <option value="24">12.00AM</option>

Convert object to array and Vice versa

function objectToArray($d) {
		if (is_object($d)) {
			// Gets the properties of the given object
			// with get_object_vars function
			$d = get_object_vars($d);
		if (is_array($d)) {
			* Return array converted to object
			* Using __FUNCTION__ (Magic constant)
			* for recursive call
			return array_map(__FUNCTION__, $d);
		else {
			// Return array
			return $d;

Maintain display order field in php

Remember I am considering following two parameters

table name - DisplayOrder
column name to reorder = O_nbr

if you need to shift the O_nbr (order number) from 10 to 1 you just need to call the method as

select UpdateOrder(10,1);
// it will return you the proper message either updated or not.. or whatever

the function code is as below –

create function UpdateOrder (fromOrder int, toOrder int) 
RETURNS varchar(50)
  DECLARE reslt varchar(50);
  DECLARE rowCount int;
  SET reslt = 'Error Occured.';
  if( fromOrder < 1) then
    SET reslt='fromOrder can not be less then 1';
  elseif(toOrder < 1) then
    SET reslt='toOrder can not be less then 1';
    select count(*) into rowCount from DisplayOrder;        
    if(rowCount < fromOrder) then
        SET reslt = concat('Sorry check again, we have only ',rowCount, ' records');
    elseif(rowCount  toOrder) then
              update DisplayOrder set O_nbr = 0 where O_nbr = fromOrder;
              Update DisplayOrder set O_nbr = O_nbr+1 where O_nbr  (toOrder-1) order by O_nbr desc;
              update DisplayOrder set O_nbr = toOrder where O_nbr = 0;
            end if;
            if(fromOrder  fromOrder AND O_nbr < (toOrder+1) order by O_nbr asc;
              update DisplayOrder set O_nbr = toOrder where O_nbr = 0;
            end if;
            SET reslt = 'Successfully done';
        end if;
    end if;         
  end if;     
  RETURN reslt;

You can replace the DisplayOrder with you table nane and O_nbr with you column name to reorder

copy the code and run it in you mysql database query window.. then to shift the order (O_nbr in DisplayOrder table) use the above described signature..

Select UpdateOrder(fromOrder,  toOrder);

if you try to run with 0 or less value, or any unsuitable condition, it will return you the error message

Select UpdateOrder(10, 0);

//returns "toOrder can not be less then 1"

Select UpdateOrder(11, 1);

//return "Sorry check again, we have only 10 records"

Select UpdateOrder(5, 5);

//returns "No Changes were made."

if you pass the correct parameter..

Select UpdateOrder(10, 2);

//returns "Successfully done"